2018.07.06 POJ1698 Alice's Chance(最大流)
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就行了。
代码如下:
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#define N 2000
#define M 100005
using namespace std;
int first[N],n,m,s,t,cnt,d[N],T,f[8];
struct edge{int v,next,c;}e[M];
inline void add(int u,int v,int c){
e[++cnt].v=v;
e[cnt].c=c;
e[cnt].next=first[u];
first[u]=cnt;
e[++cnt].v=u;
e[cnt].c=0;
e[cnt].next=first[v];
first[v]=cnt;
}
inline bool bfs(){
queue<int>q;
memset(d,-1,sizeof(d));
q.push(s),d[s]=0;
while(!q.empty()){
int x=q.front();
q.pop();
for(int i=first[x];i!=-1;i=e[i].next){
int v=e[i].v;
if(d[v]!=-1||e[i].c<=0)continue;
d[v]=d[x]+1;
if(v==t)return true;
q.push(v);
}
}
return false;
}
inline int dfs(int x,int f){
if(x==t||!f)return f;
int flow=f;
for(int i=first[x];i!=-1;i=e[i].next){
int v=e[i].v;
if(d[v]==d[x]+1&&e[i].c>0&&flow){
int tmp=dfs(v,min(flow,e[i].c));
if(!tmp)d[v]=-1;
e[i].c-=tmp;
e[i^1].c+=tmp;
flow-=tmp;
}
}
return f-flow;
}
inline int read(){
int ans=0;
char ch=getchar();
while(!isdigit(ch))ch=getchar();
while(isdigit(ch))ans=(ans<<3)+(ans<<1)+ch-'0',ch=getchar();
return ans;
}
int main(){
T=read();
while(T--){
n=read(),s=0,cnt=-1;
int maxn=0,ans=0;
memset(first,-1,sizeof(first));
memset(e,0,sizeof(e));
for(int i=1;i<=n;++i){
for(int j=1;j<=7;++j)f[j]=read();
int d=read(),w=read();
maxn=max(maxn,w);
add(s,i,d);
for(int j=1;j<=7;++j)if(f[j])for(int k=0;k<w;++k)add(i,n+j+k*7,1);
}
t=n+1+7*maxn;
for(int i=1;i<=7;++i)
for(int j=0;j<maxn;++j)
add(n+i+j*7,t,1);
while(bfs())ans+=dfs(s,0x3f3f3f3f);
bool f=true;
for(int i=first[s];i!=-1;i=e[i].next)if(e[i].c>0){f=false;break;}
if(f)puts("Yes");
else puts("No");
}
return 0;
}
2018.07.06 POJ1698 Alice's Chance(最大流)的更多相关文章
- 2018.07.06 洛谷P2936 [USACO09JAN]全流Total Flow(最大流)
P2936 [USACO09JAN]全流Total Flow 题目描述 Farmer John always wants his cows to have enough water and thus ...
- 2018.07.06 POJ1273 Drainage Ditches(最大流)
Drainage Ditches Time Limit: 1000MS Memory Limit: 10000K Description Every time it rains on Farmer J ...
- 2018.07.06 POJ1556 The Doors(最短路)
The Doors Time Limit: 1000MS Memory Limit: 10000K Description You are to find the length of the shor ...
- EZ 2018 07 06 NOIP模拟赛
又是慈溪那边给的题目,这次终于没有像上次那样尴尬了, T1拿到了较高的暴力分,T2没写炸,然后T3写了一个优雅的暴力就203pts,Rank3了. 听说其它学校的分数普遍100+,那我们学校还不是强到 ...
- 2018.07.06 BZOJ 1588: HNOI2002营业额统计(非旋treap)
1588: [HNOI2002]营业额统计 Time Limit: 5 Sec Memory Limit: 162 MB Description 营业额统计 Tiger最近被公司升任为营业部经理,他上 ...
- 2018.07.06 BZOJ1208: HNOI2004宠物收养所(非旋treap)
1208: [HNOI2004]宠物收养所 Time Limit: 10 Sec Memory Limit: 162 MB Description 最近,阿Q开了一间宠物收养所.收养所提供两种服务:收 ...
- 2018.07.06 POJ 1459 Power Network(多源多汇最大流)
Power Network Time Limit: 2000MS Memory Limit: 32768K Description A power network consists of nodes ...
- 2018.07.06 POJ2536 Gopher II(二分图匹配)
Gopher II Time Limit: 2000MS Memory Limit: 65536K Description The gopher family, having averted the ...
- [poj1698]Alice's Chance[网络流]
[转]原文:http://blog.csdn.net/wangjian8006/article/details/7926040 题目大意:爱丽丝要拍电影,有n部电影,规定爱丽丝每部电影在每个礼拜只有固 ...
随机推荐
- 5 Python3 函数进阶&迭代器与生成器
1.函数进阶 1.1.名称空间 又名name space, 顾名思义就是存放名字的地方,存什么名字呢?举例说明,若变量x=1,1存放于内存中,那名字x存放在哪里呢?名称空间正是存放名字x与1绑定关系的 ...
- MCI 录制指定格式音频
可先用其他格式转换软件转换一段0秒指定格式的音频,然后用mcisendstring(L"open xxx.avi alias abc",0,0,0)打开,在进行录音mcisends ...
- vim-git for window 默认编辑器
vim其实是linux的一个文本编辑器,所以 vi+文件名 后,其实是进入vi程序了.vi有两种模式,编辑模式和命令模式 在命令模式下,我们可以直接按 i ,此时就会切换到编辑模式,如上图,下方有个i ...
- 原生js实现三级复选框
工作中要做一个三级的复选框,用js实现了一下,从项目中把相关代码抽取出来了,有相关需求的可以参考一下.亲测可用. <!DOCTYPE html> <html> <head ...
- tnsping 命令解析
C:\Users\nowhill>tnsping jljcz Oracle Net 工具(命令)tnsping,是一个OSI会话层的工具,它用来: 1)验证名字解析(name resolutio ...
- Python 3 学习笔记(2)
输入输出 str() 函数人类可读,repr() 解释器可读 rjust() 靠右,ljust() 靠左,center() 居中.zfill() 填0. 名字空间 名字到对象的映射关系被称为名字空间. ...
- 3.3 JSP内置对象概述
1.request 1.1 request获取页面传来的参数,参数通过浏览器网址和后面添加?的方式传达. 传参:”show.jsp?id=001” 获取参数:request.getParameter( ...
- linux一些基本常识(四)
tail -f时时监控 一开启内存最小位u原则,尽量优化代码 grep -v "" /etc/passwd 这样行不行 怎么清除last nice调整进程运行级别 pkill是匹配 ...
- ionic 2,带着运气成分
npm config set loglevel info 查看安装信息 npm cache clean 清除缓存 cnpm sync ionic ...
- SSL原理分析
SSL协议的工作流程: 服务器认证阶段: 1)客户端向服务器发送一个开始信息“Hello”以便开始一个新的会话连接: 2)服务器根据客户的信息确定是否需要生成新的主密钥,如需要则 ...