DLX(精确覆盖) HDU 3663 Power Stations

Power Stations

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1735    Accepted Submission(s): 472
Special Judge


Problem Description

 

There are N towns in our country, and some of them are connected by electricity cables. It is known that every town owns a power station. When a town’s power station begins to work, it will provide electric power for this town and the neighboring towns which are connected by cables directly to this town. However, there are some strange bugs in the electric system –One town can only receive electric power from no more than one power station, otherwise the cables will be burned out for overload.

The power stations cannot work all the time. For each station there is an available time range. For example, the power station located on Town 1 may be available from the third day to the fifth day, while the power station on Town 2 may be available from the first day to the forth day. You can choose a sub-range of the available range as the working time for each station. Note that you can only choose one sub-range for each available range, that is, once the station stops working, you cannot restart it again. Of course, it is possible not to use any of them.

Now you are given all the information about the cable connection between the towns, and all the power stations’ available time. You need to find out a schedule that every town will get the electricity supply for next D days, one and only one supplier for one town at any time.
 


 

Input

 

There are several test cases. The first line of each test case contains three integers, N, M and D (1 <= N <= 60, 1 <= M <= 150, 1 <= D <= 5), indicating the number of towns is N, the number of cables is M, and you should plan for the next D days.  

Each of the next M lines contains two integers a, b (1 <= a, b <= N), which means that Town a and Town b are connected directly. Then N lines followed, each contains two numbers si and ei, (1 <= si <= ei <= D) indicating that the available time of Town i’s power station is from the si-th day to the ei-th day (inclusive).
 


 

Output

 

For each test case, if the plan exists, output N lines. The i-th line should contain two integers ui and vi, indicating that Town i’s power station should work from the ui-th day to vi-day (inclusive). If you didn’t use this power station at all, set ui = vi = 0.

If the plan doesn’t exist, output one line contains “No solution” instead.  

Note that the answer may not be unique. Any correct answers will be OK.

Output a blank line after each case.
 


 

Sample Input

 

  
  
3 3 5 1 2 2 3 3 1 1 5 1 5 1 5 4 4 5 1 2 2 3 3 4 4 1 1 5 1 5 1 5 1 5
 


 

Sample Output

 

  
  
1 5 0 0 0 0 No solution
 


 

Source

 

 

 

题意:给出村子的相邻关系,每个村子有一个供电站,供电时间是si~ei, 你能够选择其中的一段连续的时间供电,如果一个村子正在供电,跟他相邻的村子也能用电。但是每个村子只能被一个供电站供电。不然会被烧掉。而且每个村子的供电一旦停止了,就不能再次开启了。问怎么样安排能让所有的村子在D天内都有电用。

 

思路:我们设计一下列表示的状态,列表示的是某个村子在某个时间有电用。行的话表示某个村子在[l,r]内主动供电。这样子状态基本设计好了,由于每个村子只能发一次电,所以我们多加n列表示某个村子是否已经发过电了。但是这些列是不一定要覆盖的。 我们同样能用精确覆盖的方法来做。具体请看代码

 

代码:

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
using namespace std;
const int maxc = 60 * 6;
const int maxn = maxc * 60 * 25;
#define FOR(i,s,A) for(int i=A[s];i!=s;i=A[i]) 
int U[maxn], D[maxn], L[maxn], R[maxn];
int S[maxc], cnt;
int l[maxn], r[maxn], vge[maxn], col[maxn];
inline void LrRemove(int x) { L[R[x]] = L[x]; R[L[x]] = R[x]; }
inline void LrResume(int x) { L[R[x]] = R[L[x]] = x; }
inline void UdRemove(int x) { U[D[x]] = U[x]; D[U[x]] = D[x]; }
inline void UdResume(int x) { U[D[x]] = D[U[x]] = x; }

void RemoveColumn(int c)
{
	if (c == 3 * 5 + 1)
		char a = 'a';

	LrRemove(c);
	FOR(i, c, D) {
		FOR(j, i, R) {
			--S[col[j]];
			UdRemove(j);
		}
	}
}

void ResumeColumn(int c)
{
	FOR(i, c, U) {
		FOR(j, i, L) {
			++S[col[j]];
			UdResume(j);
		}
	}
	LrResume(c);
}


bool adj[65][65];
int si[65], ei[65];
vector<int> column;
int n, m, d;

void add_row(int l, int r, int vge)
{
	sort(column.begin(), column.end());
	int z = unique(column.begin(), column.end()) - column.begin();
	column.erase(column.begin() + z, column.end());
	int q = cnt;
	for (int i = 0; i < column.size(); ++i) {
		int c = column[i];
		L[cnt] = cnt - 1; R[cnt] = cnt + 1;
		U[cnt] = U[c]; D[cnt] = c;
		D[U[cnt]] = cnt; U[c] = cnt;
		++S[c];
		::l[cnt] = l, ::r[cnt] = r, ::vge[cnt] = vge;
		col[cnt] = c;
		++cnt;
	}
	L[q] = cnt - 1; R[cnt - 1] = q;
}

void init()
{
	memset(S, 0, sizeof(S));
	cnt = 0;
	for (int i = 0; i <= n*d + n; ++i) {
		L[i] = i - 1; R[i] = i + 1;
		U[i] = D[i] = i;
		col[i] = i;
		++cnt;
	}
	L[0] = cnt - 1; R[cnt - 1] = 0;
}

void input()
{
	init();
	memset(adj, 0, sizeof(adj));
	while (m--) {
		int u, v; scanf("%d%d", &u, &v);
		adj[u][v] = adj[v][u] = true;
	}
	for (int i = 1; i <= n; ++i) adj[i][i] = true;
	for (int i = 1; i <= n; ++i) scanf("%d%d", si + i, ei + i);
	for (int i = 1; i <= n; ++i) {
		for (int s = si[i]; s <= ei[i];++s)
		for (int e = s; e <= ei[i]; ++e) {
			column.clear();
			for (int j = 1; j <= n; ++j) if (adj[i][j])
			{
				for (int k = s; k <= e; ++k)
					column.push_back((j - 1)*d + k);
			}
			column.push_back(n*d + i);
			add_row(s, e, i);
		}
	}
}


int stk[maxn], top;
int outl[65], outr[65], outvge[65];

bool dfs()
{
	if (R[0] > n*d || R[0]==0)
		return true;
	int c = R[0];
	for (int i = R[0]; i <= n*d&&i != 0; i = R[i]) 
	if (S[c] > S[i]) c = i;
	if (S[c] == 0) return false;
	RemoveColumn(c);
	FOR(i, c, D) {
		FOR(j, i, R) RemoveColumn(col[j]);
	//	printf("%d %d %d\n", vge[i], l[i], r[i]);
		stk[top++] = i;
		if (dfs()) return true;
		--top;
		FOR(j, i, L) ResumeColumn(col[j]);
	}
	ResumeColumn(c);
	return false;
}

void solve()
{
	top = 0;
	if (!dfs()) printf("No solution\n");
	else {
		memset(outl, 0, sizeof(outl));
		memset(outr, 0, sizeof(outr));
		memset(outvge, 0, sizeof(outvge));
		for (int i = 0; i < top; ++i) {
			int x = stk[i];
			outl[vge[x]] = l[x];
			outr[vge[x]] = r[x];
		}
		for (int i = 1; i <= n; ++i) printf("%d %d\n", outl[i], outr[i]);
	}
}

int main()
{
	while (scanf("%d%d%d", &n, &m, &d) == 3)
	{
		input();
		solve();
	}
}


 

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
下面只是目标目录 ├─第1章-Shiro权限实战课程介绍 │ 1-1Shiro权限实战课程介绍.mp4 │ 1-2权限控制和初学JavaWeb处理访问权限控制.mp4 │ ├─第2章-大话权限框架核心知识ACL和RBAC │ 2-1权限框架设计之ACL和RBAC讲解.mp4 │ 2-2主流权限框架介绍和技术选型讲解.mp4 │ ├─第3章-ApacheShiro基础概念知识和架构讲解 │ 3-1Shiro核心知识之架构图交互和四大模块讲解.mp4 │ 3-2用户访问Shrio权限控制运行流程和常见概念讲解.mp4 │ ├─第4章-Springboot2.x整合ApacheShiro快速上手实战 │ 4-1SpringBoot2.x整合Shiro.mp4 │ 4-2快速上手之Shiro认证和授权流程实操上集.mp4 │ 4-3Shiro认证和授权流程和常用API梳理下集.mp4 │ ├─第5章-详细讲解ApacheShirorealm实战 │ 5-1Shiro安全数据来源之Realm讲解.mp4 │ 5-2快速上手之Shiro内置IniRealm实操.mp4 │ 5-3快速上手之Shiro内置JdbcRealm实操.mp4 │ 5-4ApacheShiro自定义Readl实战.mp4 │ 5-5深入Shiro源码解读认证授权流程.mp4 │ ├─第6章-Shiro权限认证Web案例知识点讲解 │ 6-1Shiro内置的Filter过滤器讲解.mp4 │ 6-2Shiro的Filter配置路径讲解.mp4 │ 6-3Shiro数据安全之数据加解密.mp4 │ 6-4Shiro权限控制注解和编程方式讲解.mp4 │ 6-5Shiro缓存模块讲解.mp4 │ 6-6ShiroSession模块讲解.mp4 │ ├─第7章-ApacheShiro整合SpringBoot2.x综合案例实战 │ 7-10使用ShiroLogout和加密处理.mp4 │ 7-1Shiro整合SpringBoot2.x案例实战介绍.mp4 │ 7-2基于RBAC权限控制实战之Mysql数据库设计.mp4 │ 7-3SpringBoot2.x项目框架和依赖搭建.mp4 │ 7-4案例实战之权限相关服务接口开发.mp4 │ 7-5案例实战之用户角色权限多对多关联查询SQL.mp4 │ 7-6案例实战自定义CustomRealm实战.mp4 │ 7-7项目实战之ShiroFilterFactoryBean配置实战.mp4 │ 7-8前后端分离自定义SessionManager验证.mp4 │ 7-9API权限拦截验证实战.mp4 │ ├─第8章-权限控制综合案例实战进阶 │ 8-1实战进阶之自定义ShiroFilter过滤器上集.mp4 │ 8-2实战进阶之自定义ShiroFilter过滤器下集.mp4 │ 8-3性能提升之Redis整合CacheManager.mp4 │ 8-4性能提升之Redis整合SessionManager.mp4 │ 8-5ShiroConfig常用bean类配置.mp4 │ ├─第9章-大话分布式应用的鉴权方式 │ 9-1单体应用到分布式应用下的鉴权方式介绍.mp4 │ 9-2Shiro整合SpringBoot下自定义SessionId.mp4 │ ├─第10章-Shiro课程总结 │ 10-1Apacheshiro从入门到高级实战课程总结.mp4 │ 10-2高级工程师到架构师-解决问题思路+学习方法.mp4 │ └─课件资料.zip

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值