将星期拆点,符合条件的连边,最后统计汇点流量是否满即可了,注意结点编号。

#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&#39;s Chance 拆点最大流的更多相关文章

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

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

  2. poj 1698 Alice‘s Chance

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

  3. POJ 1698 Alice's Chance

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

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

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

  5. poj 1698 Alice's Chance 最大流

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

  6. Alice&#39;s Chance

    id=1698" style="background-color:rgb(51,255,51)">主题链接 意甲冠军: 爱丽丝要拍电影.有n部电影,规定爱丽丝第i部 ...

  7. POJ 3422 Kaka&#39;s Matrix Travels(费用流)

    POJ 3422 Kaka's Matrix Travels 题目链接 题意:一个矩阵.从左上角往右下角走k趟,每次走过数字就变成0,而且获得这个数字,要求走完之后,所获得数字之和最大 思路:有点类似 ...

  8. POJ 2391 Ombrophobic Bovines(二分+拆点+最大流)

    http://poj.org/problem?id=2391 题意: 给定一个无向图,点i处有Ai头牛,点i处的牛棚能容纳Bi头牛,求一个最短时间T,使得在T时间内所有的牛都能进到某一牛棚里去. 思路 ...

  9. POJ 2391 Ombrophobic Bovines ★(Floyd+二分+拆点+最大流)

    [题意]有n块草地,一些奶牛在草地上吃草,草地间有m条路,一些草地上有避雨点,每个避雨点能容纳的奶牛是有限的,给出通过每条路的时间,问最少需要多少时间能让所有奶牛进入一个避雨点. 和POJ2112很类 ...

随机推荐

  1. wireshark教程

    Wireshark世界上最流行的网络分析工具. 这个强大的工具能够捕捉网络中的数据,并为用户提供关于网络和上层协议的各种信息.与非常多其它网络工具一样.Wireshark也使用pcap network ...

  2. MVC json

    1. .net MVC中Controller 在mvc中所有的controller类都必须使用"Controller"后缀来命名 并且对Action也有一定的要求: 必须是一个pu ...

  3. ORACLE单字符函数的函数

     1.           ASCII(C) 说明:返回C的首字符在ASCII码中相应的十进制 举例: SQL>SELECT ASCII('A') A,ASCII('a') B,ASCII( ...

  4. 使用cm-12.0源代码编译twrp

    Select the newest branch available. This step is not necessary with Omni because Omni already includ ...

  5. Linux高性能server规划——多线程编程(在)

    多线程编程 Linux主题概述 线程模型 线程是程序中完毕一个独立任务的完整执行序列.即一个可调度的实体. 依据执行环境和调度者的身份.线程可分为内核线程和用户线程.内核线程,在有的系统上也称为LWP ...

  6. MONGO DB windows 设备

    1,下载安装包 https://fastdl.mongodb.org/win32/mongodb-win32-x86_64-2008plus-ssl-3.0.0-signed.msi?_ga=1.22 ...

  7. 非常棒的Visual Studo调试插件:OzCode 2.0 下载地址

    最新版下载地址 http://download.csdn.net/detail/simadi/8925511 如果你是一名C#开发者,那么,你则需要OzCode.它将可视化调试的概念上升到了一个新的高 ...

  8. android--jenkins+gradle+android自动化构建apk步骤(转)

    第一步,安装jenkins,这个网上教程挺多的. 第二步,下载并配置gradle.下载地址http://www.gradle.org/ 解压gradle至某路径下,如/usr/local/lib/gr ...

  9. LinuxDLL加载优化方案

    作者:zhanhailiang 日期:2014-10-26 linux程序动态库载入流程简单介绍 linux从程序(program或对象)变成进程(process或进程),简单说来须要经过三步: fo ...

  10. Machine Learning—Linear Regression

    Evernote的同步分享:Machine Learning-Linear Regression 版权声明:本文博客原创文章.博客,未经同意,不得转载.