首页 > 代码库 > HDU5090 Game with Pearls
HDU5090 Game with Pearls
/* HDU5090 Game with Pearls http://acm.hdu.edu.cn/showproblem.php?pid=5090 匈牙利算法 * */ #include<stdio.h> #include<algorithm> using namespace std; const int Nmax=305; int t,n,k,x,ans; int match[Nmax],book[Nmax],map[Nmax][Nmax]; int init() { ans=0; for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) map[i][j]=0; for(int i=1;i<=n;i++) match[i]=book[i]=0; } int dfs(int u) { for(int i=1;i<=n;i++) { if(map[i][u] && !book[i]) { book[i]=1; if(!match[i] || dfs(match[i])) { match[i]=u; return 1; } } } return 0; } int main() { scanf("%d",&t); while(t--) { scanf("%d%d",&n,&k); init(); for(int i=1;i<=n;i++) { scanf("%d",&x); for(int j=x;j<=n;j+=k) map[j][i]=1; } for(int i=1;i<=n;i++) { for(int j=1;j<=n;j++) book[j]=0; if(dfs(i)) ans++; } if(ans==n) printf("Jerry\n"); else printf("Tom\n"); } return 0; }
HDU5090 Game with Pearls
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。