poj 1698 Alice's Chance 最大流
题目:给出n部电影的可以在周几拍摄、总天数、期限,问能不能把n部电影接下来。
分析:
对于每部电影连上源点,流量为总天数。
对于每一天建立一个点,连上汇点,流量为为1。
对于每部电影,如果可以在该天拍摄,则连上一条流量为1的边。
跑一次最大流。。。
#include <set>
#include <map>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <string>
#include <vector>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm> using namespace std; typedef long long ll;
typedef unsigned long long ull; #define debug puts("here")
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define foreach(i,vec) for(unsigned i=0;i<vec.size();i++)
#define pb push_back
#define RD(n) scanf("%d",&n)
#define RD2(x,y) scanf("%d%d",&x,&y)
#define RD3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define RD4(x,y,z,w) scanf("%d%d%d%d",&x,&y,&z,&w)
#define All(vec) vec.begin(),vec.end()
#define MP make_pair
#define PII pair<int,int>
#define PQ priority_queue
#define cmax(x,y) x = max(x,y)
#define cmin(x,y) x = min(x,y)
#define Clear(x) memset(x,0,sizeof(x))
/* #pragma comment(linker, "/STACK:1024000000,1024000000") int size = 256 << 20; // 256MB
char *p = (char*)malloc(size) + size;
__asm__("movl %0, %%esp\n" :: "r"(p) ); */ /******** program ********************/ const int MAXN = 1005;
const int MAXM = 100005;
const int INF = 1e9; int po[MAXN],tol;
int gap[MAXN],dis[MAXN],arc[MAXN],pre[MAXN],cur[MAXN];
int n,m,vs,vt; struct Edge{
int y,f,next;
}edge[MAXM]; void Add(int x,int y,int f){
edge[++tol].y = y;
edge[tol].f = f;
edge[tol].next = po[x];
po[x] = tol;
}
void add(int x,int y,int f){
Add(x,y,f);
Add(y,x,0);
} int sap(){
memset(dis,0,sizeof(dis));
memset(gap,0,sizeof(gap));
gap[0] = vt;
rep1(i,vt)
arc[i] = po[i]; int ans = 0;
int aug = INF;
int x = vs; while(dis[vs]<vt){
bool ok = false;
cur[x] = aug;
for(int i=arc[x];i;i=edge[i].next){
int y = edge[i].y;
if(edge[i].f>0&&dis[y]+1==dis[x]){
ok = true;
pre[y] = arc[x] = i;
aug = min(aug,edge[i].f);
x = y;
if(x==vt){
ans += aug;
while(x!=vs){
edge[pre[x]].f -= aug;
edge[pre[x]^1].f += aug;
x = edge[pre[x]^1].y;
}
aug = INF;
}
break;
}
}
if(ok)
continue;
int MIN = vt-1;
for(int i=po[x];i;i=edge[i].next)
if(edge[i].f>0&&dis[edge[i].y]<MIN){
MIN = dis[edge[i].y];
arc[x] = i;
}
if(--gap[dis[x]]==0)
break;
dis[x] = ++ MIN;
++ gap[dis[x]];
if(x!=vs){
x = edge[pre[x]^1].y;
aug = cur[x];
}
}
return ans;
} int f[10],w,d; int main(){ #ifndef ONLINE_JUDGE
freopen("sum.in","r",stdin);
//freopen("sum.out","w",stdout);
#endif int ncase;
RD(ncase);
while(ncase--){
Clear(po);
tol = 1;
vs = MAXN-3;
vt = vs+1; int ans = 0;
int t = 0;
RD(n);
rep1(i,n){
rep(j,7)
RD(f[j]);
RD2(d,w);
ans += d; add(vs,i,d);
w *= 7;
rep(j,w)
if(f[j%7])
add(i,j+n+1,1); cmax(t,w);
}
rep1(i,t)
add(i+n,vt,1);
ans -= sap();
puts(ans==0?"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 1698 Alice's Chance
Description Alice, a charming girl, have been dreaming of being a movie star for long. Her chances w ...
- 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 ...
- Alice's Chance POJ - 1698(按时间点建边)
Alice's Chance Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 7791 Accepted: 3174 De ...
- 2018.07.06 POJ1698 Alice's Chance(最大流)
Alice's Chance Time Limit: 1000MS Memory Limit: 10000K Description Alice, a charming girl, have been ...
- POJ 1698 最大流
Alice's Chance Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 7327 Accepted: 2992 De ...
- 【POJ 1698】Alice's Chance(二分图多重匹配)
http://poj.org/problem?id=1698 电影和日子匹配,电影可以匹配多个日子. 最多有maxw*7个日子. 二分图多重匹配完,检查一下是否每个电影都匹配了要求的日子那么多. #i ...
随机推荐
- [XAF]如何在非按钮事件中打开视图
private static void OpenDetailView(XafApplication app) { IObjectSpace os = app.CreateObjectSpace(); ...
- Form实现主从块金额汇总
1.FORM使用app_calculate.running_total汇总行金额,行上有编码重复验证. 情况一:当录入多个编码重复的行并保存时,报错,清除一个重复行再保存(头行金额一致),报错&quo ...
- chrome浏览器下用jQuery的load函数来跨域加载页面,响应状态status为(canceled)是什么情况? JSON和JSONP,也许你会豁然开朗,含jQuery用例
http://www.cnblogs.com/dowinning/archive/2012/04/19/json-jsonp-jquery.html 问题来源:http://q.cnblogs.com ...
- Slony-I中对storelisten出错的处理
客户质询的现象是: Slony-I运行中,log中发现FATAL信息: FATAL storeListen: unknown node ID 出现了上述错误后,再看后继的log,又恢复正常运行了. 客 ...
- JDBC连接各种数据库的方法(经典)
1)连接Oracle 8/8i/9i/10g/11g(thin模式) Class.forName("oracle.JDBC.driver.OracleDriver").newIns ...
- JQuery动画插件Velocity.js发布:更快的动画切换速度
5月3日,Julian在其GitHub上发布了Velocity.js.Velocity.js是一款动画切换的jQuery插件,它重新实现了jQuery的$.animate()方法从而加快动画切换的速度 ...
- Gym 100531H Problem H. Hiking in the Hills 二分
Problem H. Hiking in the Hills 题目连接: http://codeforces.com/gym/100531/attachments Description Helen ...
- SGU 538. Emoticons 水题
538. Emoticons 题目连接: http://acm.sgu.ru/problem.php?contest=0&problem=538 Description A berland n ...
- JBoss提供的常用的对称加密算法
package com.test.resteasy; import java.io.File; import java.net.MalformedURLException; import java.n ...
- git常见问题
一.设置git的user name和email: git config --global user.name "lei.li" git config --global user.e ...