poj 1698 Alice's Chance 二分图多重匹配
2015-05-13 15:35
260 查看
题意:
一个演员要拍n部电影,每部电影只能在一周的特定几天拍(如周2,周4,周5),第i部电影要拍di天,必须要在wi周拍完,问演员是否可以完成任务。
分析:
建二分图,转化为二分图的多重匹配。
代码:
一个演员要拍n部电影,每部电影只能在一周的特定几天拍(如周2,周4,周5),第i部电影要拍di天,必须要在wi周拍完,问演员是否可以完成任务。
分析:
建二分图,转化为二分图的多重匹配。
代码:
//poj 1698 //sep9 #include <iostream> using namespace std; const int maxX=64*7; const int maxY=64; int g[maxX][maxY],match[maxY][maxX]; int vis[maxY]; int x,n; struct FILM{ int a[10]; int need_day; int finish_week; }film[32]; int dfs(int x) { int i,j; for(i=0;i<n;++i){ if(vis[i]==0&&g[x][i]==1){ vis[i]=1; if(match[i][0]<film[i].need_day){ match[i][++match[i][0]]=x; return 1; } else{ for(j=1;j<=match[i][0];++j) if(dfs(match[i][j])==1){ match[i][j]=x; return 1; } } } } return 0; } void mulmatch() { int i,j; for(i=0;i<n;++i) match[i][0]=0; for(i=0;i<=x;++i){ memset(vis,0,sizeof(vis)); dfs(i); } } int main() { int cases; scanf("%d",&cases); while(cases--){ memset(g,0,sizeof(g)); scanf("%d",&n); for(int i=0;i<n;++i){ for(int j=0;j<7;++j) scanf("%d",&film[i].a[j]); scanf("%d%d",&film[i].need_day,&film[i].finish_week); } x=-1; for(int i=0;i<n;++i) for(int j=0;j<film[i].finish_week;++j) for(int k=0;k<7;++k) if(film[i].a[k]==1){ x=max(x,j*7+k); g[j*7+k][i]=1; } mulmatch(); int ok=1; for(int i=0;i<n;++i) if(match[i][0]<film[i].need_day){ ok=0; break; } if(ok==1) puts("Yes"); else puts("No"); } return 0; }
相关文章推荐
- POJ - 1698 Alice's Chance (二分图多重匹配)
- POJ1698 Alice's Chance(最大匹配)
- POJ 1698 Alice's Chance(最大流+拆点)
- POJ 1698 Alice's Chance 最大流
- POJ 1698 Alice's Chance 网络流(水
- poj 1698 Alice's Chance(最大流)
- poj 1698 Alice's Chance(ek算法)
- poj 1698 Alice's Chance(基础网络流·建图)
- POJ 1698--Alice's Chance【最大流 && 经典】
- POJ 1698 Alice's Chance
- poj 1698Alice's Chance 最大流模板题
- poj 1698 Alice's Chance 【最大流 判断是否满流】
- POJ_1698_Alice's Chance(最大流)
- 【网络流】:poj1698,Alice's Chance
- poj 1698 Alice's Chance 邻接表
- POJ 1698 Alice's Chance ( EK )
- poj 1698 Alice's Chance
- POJ 1698 Alice's Chance(最大流)
- poj 1698 Alice's Chance 拆点最大流
- 【POJ】1698 Alice's Chance 最大流