Alice's Chance
Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 7327   Accepted: 2992

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, 

  1. it will be made ONLY on some fixed days in a week, i.e., Alice can only work for the film on these days;
  2. Alice should work for it at least for specified number of days;
  3. 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

题意:
有n部电影需要拍摄,每部电影在一个星期内只有固定的几天可以拍,一天只能拍一种电影,并被拍完这部电影需要d天,必须在w周之内拍完,问能否全部拍完这n部电影
输入t组数据
输入n
输入n行,每行9个数,前七个表示这部电影在一周之内那几点可以拍(1表示可以拍,0表示不能),后两个数d,w
代码:
//每部电影拆点,容量为拍摄需要的天数,每一天拆点容量为1(一天只能拍一个电影),然后把电影和天之间建边容量为1
//(w周共有7*w天),源点连向电影,天连向汇点,求最大流是否等于拍摄电影的总天数。
#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
using namespace std;
const int maxn=;
const int inf=0x7fffffff;
struct Edge{
int from,to,cap,flow;
Edge(int u,int v,int c,int f):from(u),to(v),cap(c),flow(f){}
};
struct Dinic{
int n,m,s,t;
vector<Edge>edges;
vector<int>g[maxn];
bool vis[maxn];
int d[maxn];
int cur[maxn];
void Init(int n){
this->n=n;
for(int i=;i<n;i++) g[i].clear();
edges.clear();
}
void Addedge(int from,int to,int cap){
edges.push_back(Edge(from,to,cap,));
edges.push_back(Edge(to,from,,));//反向弧
m=edges.size();
g[from].push_back(m-);
g[to].push_back(m-);
}
bool Bfs(){
memset(vis,,sizeof(vis));
queue<int>q;
q.push(s);
d[s]=;
vis[s]=;
while(!q.empty()){
int x=q.front();q.pop();
for(int i=;i<(int)g[x].size();i++){
Edge &e=edges[g[x][i]];
if(!vis[e.to]&&e.cap>e.flow){
vis[e.to]=;
d[e.to]=d[x]+;
q.push(e.to);
}
}
}
return vis[t];
}
int Dfs(int x,int a){
if(x==t||a==) return a;
int flow=,f;
for(int&i=cur[x];i<(int)g[x].size();i++){
Edge &e=edges[g[x][i]];
if(d[x]+==d[e.to]&&(f=Dfs(e.to,min(a,e.cap-e.flow)))>){
e.flow+=f;
edges[g[x][i]^].flow-=f;
flow+=f;
a-=f;
if(a==) break;
}
}
return flow;
}
int Maxflow(int s,int t){
this->s=s;this->t=t;
int flow=;
while(Bfs()){
memset(cur,,sizeof(cur));
flow+=Dfs(s,inf);
}
return flow;
}
}dc;
int main()
{
int t,n,a[];
scanf("%d",&t);
while(t--){
scanf("%d",&n);
dc.Init();
int sum=;
for(int i=;i<=n;i++){
for(int j=;j<=;j++)
scanf("%d",&a[j]);
sum+=a[];
dc.Addedge(i,i+n,a[]);
for(int j=;j<=;j++){
if(a[j]==) continue;
for(int k=;k<a[];k++)
dc.Addedge(i+n,j+k*+,);
}
dc.Addedge(,i,inf);
}
for(int i=;i<=;i++){
dc.Addedge(i,i+,);
dc.Addedge(i+,,inf);
}
if(dc.Maxflow(,)==sum) printf("Yes\n");
else printf("No\n");
}
return ;
}

POJ 1698 最大流的更多相关文章

  1. POJ 1698 Alice&#39;s Chance(最大流+拆点)

    POJ 1698 Alice's Chance 题目链接 题意:拍n部电影.每部电影要在前w星期完毕,而且一周仅仅有一些天是能够拍的,每部电影有个须要的总时间,问能否拍完电影 思路:源点向每部电影连边 ...

  2. poj 1698 Alice‘s Chance

    poj 1698  Alice's Chance 题目地址: http://poj.org/problem?id=1698 题意: 演员Alice ,面对n场电影,每场电影拍摄持续w周,每周特定几天拍 ...

  3. poj 3281 最大流+建图

    很巧妙的思想 转自:http://www.cnblogs.com/kuangbin/archive/2012/08/21/2649850.html 本题能够想到用最大流做,那真的是太绝了.建模的方法很 ...

  4. poj 1698 Alice's Chance 最大流

    题目:给出n部电影的可以在周几拍摄.总天数.期限,问能不能把n部电影接下来. 分析: 对于每部电影连上源点,流量为总天数. 对于每一天建立一个点,连上汇点,流量为为1. 对于每部电影,如果可以在该天拍 ...

  5. 图论--网络流--最大流--POJ 1698 Alice's Chance

    Description Alice, a charming girl, have been dreaming of being a movie star for long. Her chances w ...

  6. poj 1698 Alice&#39;s Chance 拆点最大流

    将星期拆点,符合条件的连边,最后统计汇点流量是否满即可了,注意结点编号. #include<cstdio> #include<cstring> #include<cmat ...

  7. UVA 820 --- POJ 1273 最大流

    找了好久这两个的区别...UVA820 WA了 好多次.不过以后就做模板了,可以求任意两点之间的最大流. UVA 是无向图,因此可能有重边,POJ 1273是有向图,而且是单源点求最大流,因此改模板的 ...

  8. 【POJ 1698】Alice's Chance(二分图多重匹配)

    http://poj.org/problem?id=1698 电影和日子匹配,电影可以匹配多个日子. 最多有maxw*7个日子. 二分图多重匹配完,检查一下是否每个电影都匹配了要求的日子那么多. #i ...

  9. poj 1273 最大流

    题目链接:http://poj.org/problem?id=1273 a.EK算法:(Edmond-Karp): 用BFS不断找增广路径,当找不到增广路径时当前流量即为最大流. b.dinic算法: ...

随机推荐

  1. C中的除法,商和余数的大小、符号如何确定

    对于C中的除法,商和余数的大小.符号是如何确定的呢?在C89中,只规定了如果两个数为正整数,那么余数的符号为正,并且商的值是接近真实值的最大整数.比如5 / 2,那么商就是2,余数就是1.但是,C89 ...

  2. 第二十一次ScrumMeeting会议

    第二十一次Scrum Meeting 时间:2017/12/11 地点:SPR咖啡馆 人员:王子铭 游心 解小锐 王辰昱 李金奇 杨森 陈鑫 赵晓宇 照片: 目前工作进展 名字 今日 明天的工作 蔡帜 ...

  3. C语言 命令行参数 函数指针 gdb调试

    . 作者 : 万境绝尘 转载请注明出处 : http://blog.csdn.net/shulianghan/article/details/21551397 | http://www.hanshul ...

  4. 寒假学习计划——MOOC

    课程 西安交通大学[https://www.icourse163.org/course/XJTU-46006?tid=1002265006] 理由 本身中国大学mooc里c++课程不多,完结了能够有很 ...

  5. ACM 第四天

    A - 最短路 在每年的校赛里,所有进入决赛的同学都会获得一件很漂亮的t-shirt.但是每当我们的工作人员把上百件的衣服从商店运回到赛场的时候,却是非常累的!所以现在他们想要寻找最短的从商店到赛场的 ...

  6. C++并行编程1

    what is concurrency 我们可以一边看电视,一边唱歌.人并行非常容易理解,但是计算机呢?是不是我们一边编辑着word文档,一边听着歌,这样计算机就是在并行吗?不一定欧,如果你计算机是单 ...

  7. HDU 1995 R-汉诺塔V

    https://vjudge.net/contest/67836#problem/R 用1,2,...,n表示n个盘子,称为1号盘,2号盘,....号数大盘子就大.经典的汉诺塔问 题经常作为一个递归的 ...

  8. tab键、快捷键、默认按钮、小数点输入的使用--四则运算

    1. 窗体Tab键的顺序设置 选中窗体-视图-tab键顺序 label不适用tab键 2. 热键设置和快捷键设置 热键:无论光标在哪都可以 快捷键:出现界面后才能按 添加label 更改label的T ...

  9. vector中数据进行去重和排序

    , , , , , , ,}; std::vector<int> vec(a, a+sizeof(a)/sizeof(int) ); std::sort(vec.begin(), vec. ...

  10. arc076 F - Exhausted? (霍尔定理学习)

    题目链接 Problem Statement There are M chairs arranged in a line. The coordinate of the i-th chair ($$$1 ...