题目:Alice 要拍电影,每一天只能参与一部电影的拍摄,每一部电影只能在 Wi 周之内的指定的日子拍摄,总共需要花 Di 天时间,求能否拍完所有电影。

典型的二分图多重匹配,这里用了最大流的 dinic 算法。构图:源点向每部电影流容量为 Di 的边,电影向允许的日期流容量为 1 的边,每一天向汇点流容量为 1 的边。跑一次最大流,如果最大流等于 ∑D,那么就可以。

一开始用了多路增广忘了把流量为零的 d 设为 -1……悲剧……TLE 了。

代码:

#include <cstdio>
#include <algorithm>
#include <cstring>
#include <queue>
using namespace std; const int MAXV = 520, FILM = 400, MAXE = 15000, INF = 0x3f3f3f3f;
struct edge{
int to, cap, next;
edge(){};
edge(int to_, int cap_, int next_):to(to_), cap(cap_), next(next_){};
} es[MAXE];
int head[MAXV], d[MAXV], que[MAXV], tot, tmp[8]; void init(){
memset(head, -1, sizeof(head));
tot = 0;
} inline void add2(const int &a, const int &b, const int &cap){
// printf("%d---%d: %d\n", a, b, cap);
es[tot] = edge(b, cap, head[a]); head[a] = tot++;
es[tot] = edge(a, 0, head[b]); head[b] = tot++;
} bool bfs(int s, int t){
memset(d, -1, sizeof(d));
d[s] = 0;
int hh = 0, tt = 1;
que[0] = s;
while(hh < tt){
int u = que[hh++];
if(u == t)return true;
for(int i = head[u]; ~i; i = es[i].next){
int v = es[i].to;
if(d[v] == -1 && es[i].cap){
d[v] = d[u] + 1;
que[tt++] = v;
}
}
}
return false;
} int dfs(int s, int t, int low){
if(s == t) return low;
int ret = 0;
for(int i = head[s]; ~i; i = es[i].next){
int v = es[i].to, f = es[i].cap;
if(d[v] == d[s] + 1 && f && (f = dfs(v, t, min(low - ret, f)))){
es[i].cap -= f;
es[i^1].cap += f;
ret += f; //多路增广
if(ret == low) break;
}
}
if(!ret) d[s] = -1; //这里剪枝非常重要
return ret;
} int dinic(int s, int t){
int ans = 0;
while(bfs(s, t)){
ans += dfs(s, t, INF);
}
return ans;
} int main(){
freopen("in.txt", "r", stdin);
int T, N, D, W;
scanf("%d", &T);
while(T--){
init();
int sum = 0, day = 0;
scanf("%d", &N);
for(int i = 0; i < N; ++i){
for(int j = 1; j <= 7; ++j) scanf("%d", &tmp[j]);
scanf("%d%d", &D, &W);
day = max(day, W);
add2(0, FILM + i, D);
sum += D;
for(int w = 0; w < W; ++w){
for(int j = 1; j <= 7; ++j){
if(tmp[j]) add2(FILM + i, w * 7 + j, 1);
}
}
}
for(int i = day * 7; i > 0; --i){
add2(i, 500, 1);
}
int ans = dinic(0, 500);
if(ans == sum) printf("Yes\n");
else printf("No\n");
}
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 最大流

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

  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. 问题 A: Least Common Multiple

    题目描述 The least common multiple (LCM) of a set of positive integers is the smallest positive integer ...

  2. Hessian 2.0 序列化协议 - Hessian 2.0 Serialization Protocol 翻译

    Hessian是一种轻量.快速的web协议,在微服务场景下经常被使用. Hessian协议实际上包含两种含义: 1. Web网络通信远程调用服务,具体可以参考:http://hessian.cauch ...

  3. JAVA_四大代码块_普通代码块、构造代码块、静态代码块、同步代码块。

    普通代码块 在方法或语句中出现的{}里面的内容就被称为普通代码块,普通代码块和一般的语句执行顺序一样,由他们在代码中出现的次序决定,即--"先出现先执行". 但是不同的普通代码块即 ...

  4. winform 控件大小随着窗体自适应

    3个方法: #region 控件缩放变量        double formWidth;//窗体原始宽度        double formHeight;//窗体原始高度        doubl ...

  5. PHP+IIS上传大文件

    最近刚接触IIS服务器,在使用php上传大文件的时候,遇到了一些问题.通过查阅网上资料进行了总结,希望对各位有帮助. 第一步,检查PHP的配置. 打开php.ini配置文件 1.file_upload ...

  6. 利用java中的BigInteger实现进制转换

    [原创] java中的进制BigInteger十分的强大,而且好用,他可以表示任意大的整数,同时还可以进行进制转换,十分的方便, 代码示例: package com.jiajia.demo_1; im ...

  7. C# Lambda表达式使用累加器例子

    using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Lamb ...

  8. 从pthread 到QThread

    该文出自:http://www.civilnet.cn/bbs/topicno/78430 使用线程技术进行应用编程的意义在gemfield的文章<从进程到线程>中已经介绍过了,我们就直奔 ...

  9. SQL 视图 局部变量 全局变量 条件语句 事务 触发器

    一.视图 1.视图是一张虚拟表,他所存储的不是实际数据,而是查询语句,但我们可以对视图进行像数据表一样的操作. 2.为什么使用视图呢?我的理解是:1.在远程传输数据时,可以避免过长的查询字符,减少流量 ...

  10. 【bzoj1452】[JSOI2009]Count 二维树状数组

    题目描述 输入 输出 样例输入 样例输出 1 2 题解 二维树状数组 一开始没看到 1≤c≤100 ,想到了主X树和X块,结果发现c的范围那么小... 二维树状数组水题,和一维的一样,向上修改,向下查 ...