图论--网络流--最大流--POJ 1698 Alice's Chance
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
构图:
0号节点表源点S, 1-350号节点表示每一天(因为最多只有50周),然后350+1到350+N表示这N部电影. 351+N号节点是汇点.
源点到每部电影i有边(s, i, Di). Di表示这部电影需要拍多少天.
每天j到汇点t有边(j, t, 1).,如果电影i能在第j天拍摄,那么从i到j有边(i,j,1).然后求最大流是否满流!
#include<cstdio>
#include<cstring>
#include<queue>
#include<algorithm>
#include<vector>
#define INF 1e9
using namespace std;
const int maxn=400+5;
struct Edge
{
int from,to,cap,flow;
Edge(){}
Edge(int f,int t,int c,int fl):from(f),to(t),cap(c),flow(fl){}
};
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,int s,int t)
{
this->n=n, this->s=s, this->t=t;
edges.clear();
for(int i=0;i<n;i++) G[i].clear();
}
void AddEdge(int from,int to,int cap)
{
edges.push_back( Edge(from,to,cap,0) );
edges.push_back( Edge(to,from,0,0) );
m=edges.size();
G[from].push_back(m-2);
G[to].push_back(m-1);
}
bool BFS()
{
queue<int> Q;
memset(vis,0,sizeof(vis));
vis[s]=true;
d[s]=0;
Q.push(s);
while(!Q.empty())
{
int x= Q.front(); Q.pop();
for(int i=0;i<G[x].size();++i)
{
Edge& e=edges[G[x][i]];
if(!vis[e.to] && e.cap>e.flow)
{
vis[e.to]=true;
d[e.to]=d[x]+1;
Q.push(e.to);
}
}
}
return vis[t];
}
int DFS(int x,int a)
{
if(x==t || a==0)return a;
int flow=0,f;
for(int& i=cur[x];i<G[x].size();++i)
{
Edge& e=edges[G[x][i]];
if(d[e.to]==d[x]+1 && (f=DFS(e.to,min(a,e.cap-e.flow) ) )>0)
{
e.flow +=f;
edges[G[x][i]^1].flow -=f;
flow +=f;
a-=f;
if(a==0) break;
}
}
return flow;
}
int max_flow()
{
int ans=0;
while(BFS())
{
memset(cur,0,sizeof(cur));
ans+=DFS(s,INF);
}
return ans;
}
}DC;
int n,day_sum;//电影数,总共需要天数
int src,dst;
int can[20+5][7];//can[i][j] 表示第i部电影在一周的第j+1天是否可以拍摄
int need[20+5];
int week[20+5];
int main()
{
int T; scanf("%d",&T);
while(T--)
{
day_sum=0;
scanf("%d",&n);
src=0,dst=350+n+1;
DC.init(350+n+2,src,dst);
for(int i=1;i<=n;i++)
{
for(int j=0;j<7;j++) scanf("%d",&can[i][j]);
scanf("%d%d",&need[i],&week[i]);
DC.AddEdge(src,350+i,need[i]);
day_sum += need[i];
}
for(int i=1;i<=350;i++)//i表每一天
{
DC.AddEdge(i,dst,1);
for(int j=1;j<=n;j++)if(can[j][i%7]==1 && (i-1)/7<week[j])
{
DC.AddEdge(j+350,i,1);
}
}
printf("%s\n",DC.max_flow()==day_sum?"Yes":"No");
}
return 0;
}
图论--网络流--最大流--POJ 1698 Alice's Chance的更多相关文章
- poj 1698 Alice‘s Chance
poj 1698 Alice's Chance 题目地址: http://poj.org/problem?id=1698 题意: 演员Alice ,面对n场电影,每场电影拍摄持续w周,每周特定几天拍 ...
- 图论--网络流--最大流--POJ 3281 Dining (超级源汇+限流建图+拆点建图)
Description Cows are such finicky eaters. Each cow has a preference for certain foods and drinks, an ...
- poj 1698 Alice's Chance 最大流
题目:给出n部电影的可以在周几拍摄.总天数.期限,问能不能把n部电影接下来. 分析: 对于每部电影连上源点,流量为总天数. 对于每一天建立一个点,连上汇点,流量为为1. 对于每部电影,如果可以在该天拍 ...
- 图论--网络流--费用流POJ 2195 Going Home
Description On a grid map there are n little men and n houses. In each unit time, every little man c ...
- 图论--网络流--费用流--POJ 2156 Minimum Cost
Description Dearboy, a goods victualer, now comes to a big problem, and he needs your help. In his s ...
- 图论--网络流--最大流 POJ 2289 Jamie's Contact Groups (二分+限流建图)
Description Jamie is a very popular girl and has quite a lot of friends, so she always keeps a very ...
- POJ 1698 Alice's Chance
题目:Alice 要拍电影,每一天只能参与一部电影的拍摄,每一部电影只能在 Wi 周之内的指定的日子拍摄,总共需要花 Di 天时间,求能否拍完所有电影. 典型的二分图多重匹配,这里用了最大流的 din ...
- POJ 1698 Alice's Chance(最大流+拆点)
POJ 1698 Alice's Chance 题目链接 题意:拍n部电影.每部电影要在前w星期完毕,而且一周仅仅有一些天是能够拍的,每部电影有个须要的总时间,问能否拍完电影 思路:源点向每部电影连边 ...
- poj 1698 Alice's Chance 拆点最大流
将星期拆点,符合条件的连边,最后统计汇点流量是否满即可了,注意结点编号. #include<cstdio> #include<cstring> #include<cmat ...
随机推荐
- 打造一款 刷Java 知识的小程序(一)
一.为什么要打造 Java要学的东西太多了,所以准备把这些知识汇总到一起,而小程序是一个比较好的入口,借助微信客户端,打开方便. 二.打造成什么样 首页展示:包含了Java各大知识点模块 知识点展示: ...
- 家庭版记账本app开发完成
经过这几天关于android的相关学习,对于家庭版记账本app以及开发结束. 实现的功能为:用户的注册.登录.添加支出账单.添加收入账单.显示所有的该用户的账单情况(收入和支出).生产图表(直观的显示 ...
- Quil-delta-enhanced 简介
Quill 是一款时下非常热门的富文本编辑器,它拥有非常强大的扩展能力,可以让开发者根据自己的需要编写插件,使编辑器支持的内容类型更加丰富.它之所以能够拥有这么强大的扩展能力,一方面是因为它的架构和 ...
- AJ学IOS(20)UI之UIPickerView_点菜系统
AJ分享,必须精品 先看效果图 ## UIPickerView控件 UIPickerView用处: 用来展示很多行(row) 很多列(component )的数据,多用于电子商务的点菜,城市选择等等. ...
- 动态规划_01背包_从Dijikstra和Floyd入手,彻底理解01背包
dp一直是短板,现在从最基础的地方开始补 给定背包总容量 M ,n个商品选择,分别有价值vi,占量wi,从中取商品放入背包,令.容量和W=Σwi不超过M,令背包中的价值和V=Σvi最大 然后取法有很多 ...
- stand up meeting 1/7/2016
part 组员 今日工作 工作耗时/h 明日计划 工作耗时/h UI 冯晓云 调研下滑条的存在问题,尝试替换方案 6 全面实行替换 ...
- stand up meeting 12/9/2015
part 组员 今日工作 工作耗时/h 明日计划 工作耗时/h UI 冯晓云 -------------- -- ----------- -- PDF Reader 朱玉影 SDK终于差不 ...
- python 进阶篇 浅拷贝与深拷贝
阐述引用.浅拷贝和深拷贝前,首先需要要了解 Python 的世界里,一切皆对象,每个对象各包含一个 idendity.type 和 value. 引用(Reference) >>> ...
- 解决sublime打开文档,出现中文乱码问题
sublime text 软件中出现中文乱码,大多是因为编码格式不支持,需要安装一个插件就可以解决中文乱码问题,推荐安装 ConvertToUtf8 安装步骤: 1.按“shift + ctrl + ...
- 萌新带你开车上p站(番外篇)
本文由“合天智汇”公众号首发,作者:萌新 前言 这道题目应该是pwnable.kr上Toddler's Bottle最难的题目了,涉及到相对比较难的堆利用的问题,所以拿出来分析. 登录 看看源程序 程 ...