HDU - 3605 Escape

2012 If this is the end of the world how to do? I do not know how. But now scientists have found that some stars, who can live, but some people do not fit to live some of the planet. Now scientists want your help, is to determine what all of people can live in these planets. 

Input

More set of test data, the beginning of each data is n (1 <= n <= 100000), m (1 <= m <= 10) n indicate there n people on the earth, m representatives m planet, planet and people labels are from 0. Here are n lines, each line represents a suitable living conditions of people, each row has m digits, the ith digits is 1, said that a person is fit to live in the ith-planet, or is 0 for this person is not suitable for living in the ith planet. 
The last line has m digits, the ith digit ai indicates the ith planet can contain ai people most.. 
0 <= ai <= 100000 

Output

Determine whether all people can live up to these stars 
If you can output YES, otherwise output NO. 

Sample Input

1 1
1
1

2 2
1 0
1 0
1 1

Sample Output

YES
NO

 

       emmmm按照网络流的话应该要进行缩点,把喜欢星球相同的放在一起,用二进制表示喜欢状态,那么最多也就是2^10个状态,1000+个,之后再进行网络流。我的话直接想法是进行二分多重匹配,这道题有一点就是别用vector来存关系什么得,他的星球一共就15个,不用矩阵而用相较而言很慢得vector得话有点得不偿失;

#include<cstring>
#include<iostream>
#include<cstdio>
#include<vector>
using namespace std;
int G[100005][15];
bool vis[15];
int sum[15];
int use[15][100005];
int n, m;
int now[15];
int find(int x){
	for (int s = 1; s <= m; s++){
		if (vis[s] || !G[x][s])continue;vis[s] = 1;
		if (now[s] < sum[s]){
			use[s][++now[s]] = x;return 1;
		}
		for (int w = 1; w <= now[s]; w++){
			if (find(use[s][w])){
				use[s][w] = x;return 1;
			}
		}
	}
	return 0;
}
bool solve() {
	for (int s = 1; s <= n; s++){
		memset(vis, 0, sizeof(vis));
		if (!find(s))return 0;
	}
	return 1;
}
int main()
{
	while (~scanf("%d%d", &n, &m))
	{
		memset(now, 0, sizeof(now));
		for (int i = 1; i <= n; ++i)
			for (int j = 1; j <= m; ++j)
				scanf("%d", &G[i][j]);
		for (int i = 1; i <= m; ++i)
			scanf("%d", &sum[i]);
		if (solve()) printf("YES\n");
		else printf("NO\n");
	}
	return 0;
}

 

全部评论

相关推荐

11-15 18:39
已编辑
西安交通大学 Java
全村最靓的仔仔:卧槽,佬啥bg呢,本也是西交么
点赞 评论 收藏
分享
找不到工作死了算了:没事的,雨英,hr肯主动告知结果已经超越大部分hr了
点赞 评论 收藏
分享
评论
点赞
收藏
分享
牛客网
牛客企业服务