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;
}

 

全部评论

相关推荐

06-15 02:05
已编辑
南昌航空大学 数据分析师
Eason三木:你如果想干技术岗,那几个发公众号合唱比赛的经历就去掉,优秀团员去掉,求职没用。然后CET4这种不是奖项,是技能,放到下面的专业技能里或者单独列一个英语能力。 另外好好改改你的排版,首行缩进完全没有必要,行间距好好调调,别让字和标题背景黏在一起,你下面说能做高质量PPT你得展现出来啊,你这简历排版我用PPT做的都能比你做的好。 然后自我评价,你如果要干数据工程师,抗压能力强最起码得有吧。
点赞 评论 收藏
分享
05-26 09:07
已编辑
门头沟学院 Java
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务