Alice’s Chance

Time Limit: 1000MS Memory Limit: 10000K

Description

Alice, a charming girl, have been dreaming of being a movie star for long. Her chances will come now, for several filmmaking companies invite her to play the chief role in their new films. Unfortunately, all these companies will start making the films at the same time, and the greedy Alice doesn’t want to miss any of them!! You are asked to tell her whether she can act in all the films.

As for a film,

it will be made ONLY on some fixed days in a week, i.e., Alice can only work for the film on these days;

Alice should work for it at least for specified number of days;

the film MUST be finished before a prearranged deadline.

For example, assuming a film can be made only on Monday, Wednesday and Saturday; Alice should work for the film at least for 4 days; and it must be finished within 3 weeks. In this case she can work for the film on Monday of the first week, on Monday and Saturday of the second week, and on Monday of the third week.

Notice that on a single day Alice can work on at most ONE film.

Input

The first line of the input contains a single integer T (1 <= T <= 20), the number of test cases. Then T cases follow. Each test case begins with a single line containing an integer N (1 <= N <= 20), the number of films. Each of the following n lines is in the form of “F1 F2 F3 F4 F5 F6 F7 D W”. Fi (1 <= i <= 7) is 1 or 0, representing whether the film can be made on the i-th day in a week (a week starts on Sunday): 1 means that the film can be made on this day, while 0 means the opposite. Both D (1 <= D <= 50) and W (1 <= W <= 50) are integers, and Alice should go to the film for D days and the film must be finished in W weeks.

Output

For each test case print a single line, ‘Yes’ if Alice can attend all the films, otherwise ‘No’.

Sample Input

2

2

0 1 0 1 0 1 0 9 3

0 1 1 1 0 0 0 6 4

2

0 1 0 1 0 1 0 9 4

0 1 1 1 0 0 0 6 2

Sample Output

Yes

No

Hint

A proper schedule for the first test case:

date Sun Mon Tue Wed Thu Fri Sat

week1 film1 film2 film1 film1

week2 film1 film2 film1 film1

week3 film1 film2 film1 film1

week4 film2 film2 film2

Source

POJ Monthly–2004.07.18

一眼题,显然是简单最大流。这题要我们做的就是限制Alice" role="presentation" style="position: relative;">AliceAlice每部电影的制作次数和每一天的使用次数,以及要保证Alice" role="presentation" style="position: relative;">AliceAlice可以在不同的周选择同样的日子,那么我们将每一周的每一天当做一个点,分别让每个任务和它可以被制作的日子建边(分别与第一周的星期i" role="presentation" style="position: relative;">ii,第二周的星期i" role="presentation" style="position: relative;">ii……第w−1" role="presentation" style="position: relative;">w−1w−1周的星期i" role="presentation" style="position: relative;">ii连容量为1" role="presentation" style="position: relative;">11的边来保证每一天都只能被算一次),对于每一个任务,我们将源点与它们分别连边,容量为di" role="presentation" style="position: relative;">didi,对于每一个日子,我们将它们与汇点t" role="presentation" style="position: relative;">tt分别连边,容量为1" role="presentation" style="position: relative;">11,然后对整张图跑最大流,最后检查是不是每条从源点出发的边的剩余容量都为0" role="presentation" style="position: relative;">00就行了。

代码如下:

  1. #include<iostream>
  2. #include<cstdio>
  3. #include<cstring>
  4. #include<algorithm>
  5. #include<cmath>
  6. #include<queue>
  7. #define N 2000
  8. #define M 100005
  9. using namespace std;
  10. int first[N],n,m,s,t,cnt,d[N],T,f[8];
  11. struct edge{int v,next,c;}e[M];
  12. inline void add(int u,int v,int c){
  13. e[++cnt].v=v;
  14. e[cnt].c=c;
  15. e[cnt].next=first[u];
  16. first[u]=cnt;
  17. e[++cnt].v=u;
  18. e[cnt].c=0;
  19. e[cnt].next=first[v];
  20. first[v]=cnt;
  21. }
  22. inline bool bfs(){
  23. queue<int>q;
  24. memset(d,-1,sizeof(d));
  25. q.push(s),d[s]=0;
  26. while(!q.empty()){
  27. int x=q.front();
  28. q.pop();
  29. for(int i=first[x];i!=-1;i=e[i].next){
  30. int v=e[i].v;
  31. if(d[v]!=-1||e[i].c<=0)continue;
  32. d[v]=d[x]+1;
  33. if(v==t)return true;
  34. q.push(v);
  35. }
  36. }
  37. return false;
  38. }
  39. inline int dfs(int x,int f){
  40. if(x==t||!f)return f;
  41. int flow=f;
  42. for(int i=first[x];i!=-1;i=e[i].next){
  43. int v=e[i].v;
  44. if(d[v]==d[x]+1&&e[i].c>0&&flow){
  45. int tmp=dfs(v,min(flow,e[i].c));
  46. if(!tmp)d[v]=-1;
  47. e[i].c-=tmp;
  48. e[i^1].c+=tmp;
  49. flow-=tmp;
  50. }
  51. }
  52. return f-flow;
  53. }
  54. inline int read(){
  55. int ans=0;
  56. char ch=getchar();
  57. while(!isdigit(ch))ch=getchar();
  58. while(isdigit(ch))ans=(ans<<3)+(ans<<1)+ch-'0',ch=getchar();
  59. return ans;
  60. }
  61. int main(){
  62. T=read();
  63. while(T--){
  64. n=read(),s=0,cnt=-1;
  65. int maxn=0,ans=0;
  66. memset(first,-1,sizeof(first));
  67. memset(e,0,sizeof(e));
  68. for(int i=1;i<=n;++i){
  69. for(int j=1;j<=7;++j)f[j]=read();
  70. int d=read(),w=read();
  71. maxn=max(maxn,w);
  72. add(s,i,d);
  73. for(int j=1;j<=7;++j)if(f[j])for(int k=0;k<w;++k)add(i,n+j+k*7,1);
  74. }
  75. t=n+1+7*maxn;
  76. for(int i=1;i<=7;++i)
  77. for(int j=0;j<maxn;++j)
  78. add(n+i+j*7,t,1);
  79. while(bfs())ans+=dfs(s,0x3f3f3f3f);
  80. bool f=true;
  81. for(int i=first[s];i!=-1;i=e[i].next)if(e[i].c>0){f=false;break;}
  82. if(f)puts("Yes");
  83. else puts("No");
  84. }
  85. return 0;
  86. }

2018.07.06 POJ1698 Alice's Chance(最大流)的更多相关文章

  1. 2018.07.06 洛谷P2936 [USACO09JAN]全流Total Flow(最大流)

    P2936 [USACO09JAN]全流Total Flow 题目描述 Farmer John always wants his cows to have enough water and thus ...

  2. 2018.07.06 POJ1273 Drainage Ditches(最大流)

    Drainage Ditches Time Limit: 1000MS Memory Limit: 10000K Description Every time it rains on Farmer J ...

  3. 2018.07.06 POJ1556 The Doors(最短路)

    The Doors Time Limit: 1000MS Memory Limit: 10000K Description You are to find the length of the shor ...

  4. EZ 2018 07 06 NOIP模拟赛

    又是慈溪那边给的题目,这次终于没有像上次那样尴尬了, T1拿到了较高的暴力分,T2没写炸,然后T3写了一个优雅的暴力就203pts,Rank3了. 听说其它学校的分数普遍100+,那我们学校还不是强到 ...

  5. 2018.07.06 BZOJ 1588: HNOI2002营业额统计(非旋treap)

    1588: [HNOI2002]营业额统计 Time Limit: 5 Sec Memory Limit: 162 MB Description 营业额统计 Tiger最近被公司升任为营业部经理,他上 ...

  6. 2018.07.06 BZOJ1208: HNOI2004宠物收养所(非旋treap)

    1208: [HNOI2004]宠物收养所 Time Limit: 10 Sec Memory Limit: 162 MB Description 最近,阿Q开了一间宠物收养所.收养所提供两种服务:收 ...

  7. 2018.07.06 POJ 1459 Power Network(多源多汇最大流)

    Power Network Time Limit: 2000MS Memory Limit: 32768K Description A power network consists of nodes ...

  8. 2018.07.06 POJ2536 Gopher II(二分图匹配)

    Gopher II Time Limit: 2000MS Memory Limit: 65536K Description The gopher family, having averted the ...

  9. [poj1698]Alice's Chance[网络流]

    [转]原文:http://blog.csdn.net/wangjian8006/article/details/7926040 题目大意:爱丽丝要拍电影,有n部电影,规定爱丽丝每部电影在每个礼拜只有固 ...

随机推荐

  1. Vue2.0中v-for迭代语法变化(key、index)

    语法发生了变化:http://blog.csdn.net/sinat_35512245/article/details/53966788 新数组语法 value in arr (value, inde ...

  2. Activity服务类-3 FormService服务类

    1.获取//通过流程定义ID获取表单字段集合StartFormData startFormData = formService.getStartFormData(processDefinitionId ...

  3. xcode显示行号show gutter

    要在每一个代码编辑窗口中的边线里显示行号: 使用Xcode > Preferences 菜单命令,点击 Text Editing,然后选择Editing 然后点击选择 “Line numbers ...

  4. vue深入了解组件——处理边界情况

    一.访问元素&组件 在绝大多数情况下,我们最好不要触达另一个组件实例内部或手动操作DOM元素.不过也确实在一些情况下做这些事情是合适的. 1.1 访问根实例 在每个 new Vue 实例的子组 ...

  5. Asp.net MVC重要

    1.asp.net mvc百度解释 2.asp.net mvc各版本特点 3.asp.net mvc知多少 4.asp.net mvc4入门到精通系列目录汇总(邹琼俊)[重要] 5.新年奉献MVC+E ...

  6. mysql的collation-字符集

    utf8_general_ci               :排序规则 utf8 -- UTF-8 Unicode     :字符集 一.通过my.cnf文件增加(一劳永逸)两个参数:1.在[mysq ...

  7. inotify用法简介及结合rsync实现主机间的文件实时同步

    一.inotify简介 inotify是Linux内核2.6.13 (June 18, 2005)版本新增的一个子系统(API),它提供了一种监控文件系统(基于inode的)事件的机制,可以监控文件系 ...

  8. unity 返回子对象组件

    Component[] GetComponentsInChildren(Type t, bool includeInactive = false); //includeInactive: 是否查找非激 ...

  9. one by one 项目 part 6

    package Controllerservlet; import java.io.IOException; import java.io.PrintWriter; import java.util. ...

  10. css 设置元素背景为透明

    要设置某一元素的背景为透明,在 chrome .firefox.opera 下是这样的: rgba 中的最后一个参数 0.4 就是想要的透明度,范围在0-1之间. 在 ie 中一般是这样的: filt ...