POJ 1698 Alice's Chance(最大流+拆点)
POJ 1698 Alice's Chance
题意:拍n部电影。每部电影要在前w星期完毕,而且一周仅仅有一些天是能够拍的,每部电影有个须要的总时间,问能否拍完电影
思路:源点向每部电影连边,容量为d,然后每部电影相应能拍的那天连边,因为每天容量限制是1。所以进行拆点,然后连向汇点就可以
代码:
#include <cstdio>
#include <cstring>
#include <queue>
#include <algorithm>
using namespace std; const int MAXNODE = 1005;
const int MAXEDGE = 100005; typedef int Type;
const Type INF = 0x3f3f3f3f; struct Edge {
int u, v;
Type cap, flow;
Edge() {}
Edge(int u, int v, Type cap, Type flow) {
this->u = u;
this->v = v;
this->cap = cap;
this->flow = flow;
}
}; struct Dinic {
int n, m, s, t;
Edge edges[MAXEDGE];
int first[MAXNODE];
int next[MAXEDGE];
bool vis[MAXNODE];
Type d[MAXNODE];
int cur[MAXNODE];
vector<int> cut; void init(int n) {
this->n = n;
memset(first, -1, sizeof(first));
m = 0;
}
void add_Edge(int u, int v, Type cap) {
edges[m] = Edge(u, v, cap, 0);
next[m] = first[u];
first[u] = m++;
edges[m] = Edge(v, u, 0, 0);
next[m] = first[v];
first[v] = m++;
} bool bfs() {
memset(vis, false, sizeof(vis));
queue<int> Q;
Q.push(s);
d[s] = 0;
vis[s] = true;
while (!Q.empty()) {
int u = Q.front(); Q.pop();
for (int i = first[u]; i != -1; i = next[i]) {
Edge& e = edges[i];
if (!vis[e.v] && e.cap > e.flow) {
vis[e.v] = true;
d[e.v] = d[u] + 1;
Q.push(e.v);
}
}
}
return vis[t];
} Type dfs(int u, Type a) {
if (u == t || a == 0) return a;
Type flow = 0, f;
for (int &i = cur[u]; i != -1; i = next[i]) {
Edge& e = edges[i];
if (d[u] + 1 == d[e.v] && (f = dfs(e.v, min(a, e.cap - e.flow))) > 0) {
e.flow += f;
edges[i^1].flow -= f;
flow += f;
a -= f;
if (a == 0) break;
}
}
return flow;
} Type Maxflow(int s, int t) {
this->s = s; this->t = t;
Type flow = 0;
while (bfs()) {
for (int i = 0; i < n; i++)
cur[i] = first[i];
flow += dfs(s, INF);
}
return flow;
} void MinCut() {
cut.clear();
for (int i = 0; i < m; i += 2) {
if (vis[edges[i].u] && !vis[edges[i].v])
cut.push_back(i);
}
}
} gao; int t, n, day[10], d, w, vis[400]; int main() {
scanf("%d", &t);
while (t--) {
memset(vis, 0, sizeof(vis));
gao.init(1000);
scanf("%d", &n);
int sum = 0;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= 7; j++)
scanf("%d", &day[j]);
scanf("%d%d", &d, &w);
sum += d;
gao.add_Edge(0, i, d);
for (int j = 0; j < w; j++) {
for (int k = 1; k <= 7; k++) {
if (day[k]) {
gao.add_Edge(i, 20 + j * 7 + k, INF);
vis[20 + j * 7 + k] = 1;
}
}
}
}
for (int i = 21; i <= 370; i++) {
if (!vis[i]) continue;
gao.add_Edge(i, i + 350, 1);
gao.add_Edge(i + 350, 1000, INF);
}
printf("%s\n", gao.Maxflow(0, 1000) == sum ? "Yes" : "No");
}
return 0;
}
POJ 1698 Alice's Chance(最大流+拆点)的更多相关文章
- poj 1698 Alice's Chance 拆点最大流
将星期拆点,符合条件的连边,最后统计汇点流量是否满即可了,注意结点编号. #include<cstdio> #include<cstring> #include<cmat ...
- 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 最大流
题目:给出n部电影的可以在周几拍摄.总天数.期限,问能不能把n部电影接下来. 分析: 对于每部电影连上源点,流量为总天数. 对于每一天建立一个点,连上汇点,流量为为1. 对于每部电影,如果可以在该天拍 ...
- POJ 1698 Alice's Chance
题目:Alice 要拍电影,每一天只能参与一部电影的拍摄,每一部电影只能在 Wi 周之内的指定的日子拍摄,总共需要花 Di 天时间,求能否拍完所有电影. 典型的二分图多重匹配,这里用了最大流的 din ...
- Alice's Chance
id=1698" style="background-color:rgb(51,255,51)">主题链接 意甲冠军: 爱丽丝要拍电影.有n部电影,规定爱丽丝第i部 ...
- poj 2391 Ombrophobic Bovines, 最大流, 拆点, 二分, dinic, isap
poj 2391 Ombrophobic Bovines, 最大流, 拆点, 二分 dinic /* * Author: yew1eb * Created Time: 2014年10月31日 星期五 ...
- poj 3498 March of the Penguins(最大流+拆点)
题目大意:在南极生活着一些企鹅,这些企鹅站在一些冰块上,现在要让这些企鹅都跳到同一个冰块上.但是企鹅有最大的跳跃距离,每只企鹅从冰块上跳走时会给冰块造成损害,因此企鹅跳离每个冰块都有次数限制.找出企鹅 ...
- 【POJ 1698】Alice's Chance(二分图多重匹配)
http://poj.org/problem?id=1698 电影和日子匹配,电影可以匹配多个日子. 最多有maxw*7个日子. 二分图多重匹配完,检查一下是否每个电影都匹配了要求的日子那么多. #i ...
随机推荐
- 【07】react 之 生命周期
阅读目录(Content) 实例化 getDefaultProps getInitialState componentWillMount render componentDidMount 存在期 co ...
- hdu Rich Game 6245
Rich Game Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total S ...
- Dinic 网络流
写个博客贴板子-- inline void add_edge(int x,int y,int z){ e[++tot].x=y,e[tot].cap=z; e[tot].next=h[x],h[x]= ...
- linux把时间类型值转换为数值型
字符及字符串处理函数:字符及字符串处理函数的处理对象均为字符型数据,但其返回值类型各异.1.取子串函数:格式:substr(c,n1,n2)功能:取字符串C第n1个字符起的n2个字符.返回值类型是字符 ...
- Javascript&Html-延迟调用和间歇调用
Javascript&Html-延迟调用和间歇调用 Javascript 是一种单线程语言,所有的javascript任务都会放到一个任务列表中,这些javascript任务会按照插入到列表中 ...
- js动态添加select菜单 联动菜单
原文发布时间为:2009-11-14 -- 来源于本人的百度文章 [由搬家工具导入] <html> <head> <title>http://hi.baidu.co ...
- the project was not built since its build……
[问题描述] 用eclipse编译程序时,出现下面错误: The project was not built since its build path is incomplete. Cannot fi ...
- postgresql 10 数据类型 (完整版)
官方数据类型document https://www.postgresql.org/docs/10/static/datatype.html PostgreSQL拥有丰富的数据类型供用户使用.用户也可 ...
- Linux中查看某个软件的安装路径
Linux中查看某个软件的安装路径(地址)有时显得非常重要.比如某个文件的快速启动项被删除,或者你要建立快速启动项,或者想删除.添加安装文件等等,很多地方都要用到查案文件安装路径的命令. 这里给大家介 ...
- 洛谷 P1464 Function【动态规划(递推)/记忆化搜索(递归)】
题目描述 对于一个递归函数w(a,b,c) 如果a<=0 or b<=0 or c<=0就返回值1. 如果a>20 or b>20 or c>20就返回w(20,2 ...