题目:给出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 最大流的更多相关文章

  1. poj 1698 Alice‘s Chance

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

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

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

  3. POJ 1698 Alice's Chance

    题目:Alice 要拍电影,每一天只能参与一部电影的拍摄,每一部电影只能在 Wi 周之内的指定的日子拍摄,总共需要花 Di 天时间,求能否拍完所有电影. 典型的二分图多重匹配,这里用了最大流的 din ...

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

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

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

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

  6. Alice's Chance POJ - 1698(按时间点建边)

    Alice's Chance Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 7791   Accepted: 3174 De ...

  7. 2018.07.06 POJ1698 Alice's Chance(最大流)

    Alice's Chance Time Limit: 1000MS Memory Limit: 10000K Description Alice, a charming girl, have been ...

  8. POJ 1698 最大流

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

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

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

随机推荐

  1. [转] [Visual Studio 2012] 找回 建立單元測試 選單

    原文链接:http://www.dotblogs.com.tw/yc421206/archive/2013/03/08/95920.aspx Step1.建立選單 在VS2012選單,Tools→Cu ...

  2. ClassRequestHandler or VendorRequestHandler wIndex must be less than NumIFs

    P1_ro:20000EEA ClassRequestHandler ; CODE XREF: USB__HandleSetup+38j P1_ro:20000EEA LDRB R0, [R4,#4] ...

  3. SQL with(unlock)与with(readpast) (转)

    所有Select加 With (NoLock)解决阻塞死锁,在查询语句中使用 NOLOCK 和 READPAST 处理一个数据库死锁的异常时候,其中一个建议就是使用 NOLOCK 或者 READPAS ...

  4. C++在堆上申请和释放内存 - new & delete

    // 动态申请内存, 指向一个未初始化的整型 int *pi = new int; // pi指向一个整型值,初始化为0 int *pi = new int(); // value of i is 1 ...

  5. or1200下raw-os学习(任务篇)

    这次就来说说基于上一节介绍的系统框图去建立我们所需要的任务,顺便学习Raw-OS提供的API,根据上节的分析,对于Slave Board有如下设计: Slave Board有三个任务,分别负责测试阻抗 ...

  6. UVA 253 (13.08.06)

     Cube painting  We have a machine for painting cubes. It is supplied withthree different colors: blu ...

  7. 【原创】PostSharp入门笔记

    最近写了一个抓取软件,用户反映软件偶尔会抛异常: 由于当时写代码时没有注意异常处理,大部分方法都没有写try…catch…finally的语句,所以很难找出异常是出在哪个地方,难道要为所有方法加上tr ...

  8. android 下修改 hosts文件 及 out of memory的解决

    因为android模拟器host文件无法修改,导致无法通过域名使用http方法调用内网服务,因此从网上大量转载的一种方法,这种方法: 1. 通过emulator -avd avdName -parti ...

  9. linux入侵检测系统snort安装配置

    队长让俺瞅瞅snort,没想到安装配置都遇到问题...整理下过程,给跟我一样的家伙看看.. 由于本人机器是ubuntu,apt-get 几下就可以了,其实网上有不少这样的文章...之所以还要写就是.. ...

  10. C# 中传递多个参数给多线程

    1.方式一:使用ParameterizedThreadStart委托 如果使用了ParameterizedThreadStart委托,线程的入口必须有一个object类型的参数,且返回类型为void. ...