poj 1698 Alice's Chance 拆点最大流
将星期拆点,符合条件的连边,最后统计汇点流量是否满即可了,注意结点编号。
#include<cstdio>
#include<cstring>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<vector>
#include<string>
#define eps 1e-12
#define INF 0x7fffffff
#define maxn 1000
using namespace std;
int n,m;
int en;
int st,ed; //源点和汇点
int dis[maxn] ;//dis[i],表示 到 原点 s 的 层数
int que[999999];
int can[55][11];
struct edge
{
int to,c,next;
};
edge e[999999];
int head[maxn];
void add(int a,int b,int c)
{
e[en].to=b;
e[en].c=c;
e[en].next=head[a];
head[a]=en++;
e[en].to=a;
e[en].c=0;
e[en].next=head[b];
head[b]=en++;
}
int bfs()
{
memset(dis,-1,sizeof(dis));
dis[st]=0;
int front=0,rear=0;
que[rear++]=st;
while(front<rear)
{
int j=que[front++];
for(int k=head[j];k!=-1;k=e[k].next)
{
int i=e[k].to;
if(dis[i]==-1&&e[k].c)
{
dis[i] = dis[j]+ 1 ;
que[rear++]=i;
if(i==ed) return true;
}
}
}
return false;
}
int dfs(int x,int mx)
{
int i,a;
if(x==ed) return mx ;
int ret=0;
for(int k=head[x];k!=-1&&ret<mx;k=e[k].next)
{
if(e[k].c&&dis[e[k].to]==dis[x]+1)
{
int dd=dfs(e[k].to,min(e[k].c,mx-ret));
e[k].c-=dd;
e[k^1].c+=dd;
ret+=dd;
}
}
if(!ret) dis[x]=-1;
return ret;
}
void init()
{
en=0;
st=0; //源
ed=20+50*7+100; //汇
memset(head,-1,sizeof(head));
}
void build()
{
for(int i=1;i<=n;i++) add(i,ed,can[i][8]);
for(int i=n+1;i<=n+350;i++) add(st,i,1);
for(int i=1;i<=n;i++)
{
for(int j=0,id=n+1;j<can[i][9];j++) //第几周
{
for(int t=1;t<=7;t++,id++)
{
if(can[i][t]) add(id,i,1);
}
}
}
}
int dinic()
{
int tmp=0;
int maxflow=0;
while(bfs())
{
while(tmp=dfs(st,INF)) maxflow+=tmp;
}
return maxflow;
} int main()
{
int cas;
int ans;
scanf("%d",&cas);
while(cas--)
{
ans=0;
scanf("%d",&n);
for(int i=1;i<=n;i++)
{
for(int j=1;j<=9;j++)
{
scanf("%d",&can[i][j]);
}
ans+=can[i][8];
}
init();
build();
// cout<<dinic()<<endl;
printf("%s\n",dinic()==ans?"Yes":"No");
}
}
poj 1698 Alice's Chance 拆点最大流的更多相关文章
- POJ 1698 Alice's Chance(最大流+拆点)
POJ 1698 Alice's Chance 题目链接 题意:拍n部电影.每部电影要在前w星期完毕,而且一周仅仅有一些天是能够拍的,每部电影有个须要的总时间,问能否拍完电影 思路:源点向每部电影连边 ...
- poj 1698 Alice‘s Chance
poj 1698 Alice's Chance 题目地址: http://poj.org/problem?id=1698 题意: 演员Alice ,面对n场电影,每场电影拍摄持续w周,每周特定几天拍 ...
- POJ 1698 Alice's Chance
题目:Alice 要拍电影,每一天只能参与一部电影的拍摄,每一部电影只能在 Wi 周之内的指定的日子拍摄,总共需要花 Di 天时间,求能否拍完所有电影. 典型的二分图多重匹配,这里用了最大流的 din ...
- 图论--网络流--最大流--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. 对于每部电影,如果可以在该天拍 ...
- Alice's Chance
id=1698" style="background-color:rgb(51,255,51)">主题链接 意甲冠军: 爱丽丝要拍电影.有n部电影,规定爱丽丝第i部 ...
- POJ 3422 Kaka's Matrix Travels(费用流)
POJ 3422 Kaka's Matrix Travels 题目链接 题意:一个矩阵.从左上角往右下角走k趟,每次走过数字就变成0,而且获得这个数字,要求走完之后,所获得数字之和最大 思路:有点类似 ...
- POJ 2391 Ombrophobic Bovines(二分+拆点+最大流)
http://poj.org/problem?id=2391 题意: 给定一个无向图,点i处有Ai头牛,点i处的牛棚能容纳Bi头牛,求一个最短时间T,使得在T时间内所有的牛都能进到某一牛棚里去. 思路 ...
- POJ 2391 Ombrophobic Bovines ★(Floyd+二分+拆点+最大流)
[题意]有n块草地,一些奶牛在草地上吃草,草地间有m条路,一些草地上有避雨点,每个避雨点能容纳的奶牛是有限的,给出通过每条路的时间,问最少需要多少时间能让所有奶牛进入一个避雨点. 和POJ2112很类 ...
随机推荐
- Facebook Asynchronous Layout and Rending
Facebook Asynchronous Layout and Rending by 吴雪莹 dispatch_async(backgroundQueue, ^{ storyNode = [[FBS ...
- 【原创】leetCodeOj --- Min Stack 解题报告
题目地址: https://oj.leetcode.com/problems/min-stack/ 题目内容: Design a stack that supports push, pop, top, ...
- Easyui 异步树直接所有展开
初始化异步树直接所有展开代码: $(function(){ $('#tt').tree({ url:'<%=request.getContextPath()%>/treeInit', li ...
- Cocos2d-x项目总结中的一些遇到的问题
这几天在用Cocos2D-X尝试着做一个小游戏,当然不是创新,仅仅是单纯的模仿,就是为了将自己这段时间学到的技术应用于实践中. 在这个过程中.遇到了一些问题,在此特做一些总结,以免以后遇到类似的问题. ...
- c语言 int (*p)[5] 类型分析
#include<stdio.h> int main() { int i; int b[5]={1,3,5,7,9}; int (*a)[5] = &b ...
- Codeforces Round #270(利用prim算法)
D. Design Tutorial: Inverse the Problem time limit per test 2 seconds memory limit per test 256 mega ...
- 白学jquery Mobile《构建跨平台APP:jQuery Mobile移动应用实战》连续7-电话问卷调查
[例7-3 文本编辑框创建一个简单的调查问卷] 01 <!DOCTYPEhtml> 02 <html> 03 <head> 04 ...
- Visual Studio 2012中使用Zen Coding,写html的神器!
点工具 -扩展和更新的联机库中 找到以下俩插件 安装后重新启动 新建一个html文件.将下行代码拷贝到页面里. div>(header>div)+(section>ul>li. ...
- Linux经常使用的命令(十) - nl
nl命令在linux系统中用来计算文件里行号. nl 能够将输出的文件内容自己主动的加上行号.其默认的结果与 cat -n 有点不太一样. nl 能够将行号做比較多的显示设计,包含位数与是否自己主动补 ...
- 在SSMS里查看TDS数据包内容
原文:在SSMS里查看TDS数据包内容 在SSMS里查看TDS数据包内容 摘抄自<SQLSERVER2012实施与管理实战指南> 要具体查看TDS数据库的内容,我们可以: 用NETWORK ...