#include <iostream>
#include <queue>
#include <climits>
#include <cstring>
using namespace std;
const int MAX_SIZE = 400;
int capacity[MAX_SIZE][MAX_SIZE];
int parent[MAX_SIZE];
bool visit[MAX_SIZE]; bool Edmonds_Karp( int start, int end ){
queue<int> Q;
memset( visit, false, sizeof( visit ) );
visit[start] = true;
Q.push( start );
while( !Q.empty() ){
int temp = Q.front();
Q.pop();
for( int i = start; i <= end; ++i ){
if( capacity[temp][i] && !visit[i] ){
visit[i] = true;
parent[i] = temp;
Q.push( i );
if( i == end ) return true;
}
}
}
return false;
} int Ford_Fulkerson( int start, int end ){
int max_flow = 0;
while( true ){
if( !Edmonds_Karp( start, end ) ) break;
int flow = INT_MAX;
int path = end;
while( path != start ){
flow = min( flow, capacity[parent[path]][path] );
path = parent[path];
}
path = end;
while( path != start ){
capacity[path][parent[path]] += flow;
capacity[parent[path]][path] -= flow;
path = parent[path];
}
max_flow += flow;
}
return max_flow;
} int main(){
int t;
cin>>t;
while( t-- ){
int start = 0;
int end = MAX_SIZE - 1;
memset( capacity, 0, sizeof( capacity ) );
int film_num;
int sum_day = 0;
cin>>film_num;
for( int i = 1; i <= film_num; ++i ){
int flag[8];
int day, week;
for( int j = 1; j <= 7; ++j ) cin>>flag[j];
cin>>day>>week;
capacity[start][i] = day;
sum_day += day;
for( int p = 0; p < week; ++p ){
for( int q = 1; q <= 7; ++q ){
int index = film_num + 7 * p + q;
capacity[i][index] = flag[q];
if( flag[q] ) capacity[index][end] = 1;
}
}
}
/*
for( int i = 0; i <= film_num; ++i ){
for( int j = 0; j <= 40; ++j ){
cout<<capacity[i][j]<<" ";
}
cout<<endl;
}
cout<<endl;*/
int max_flow = Ford_Fulkerson( start, end );
if( max_flow == sum_day ) cout<<"Yes"<<endl;
else cout<<"No"<<endl;
}
return 0;
}

POJ_1698_Alice's Chance的更多相关文章

  1. Chance – 功能强大的 JavaScript 随机数生成类库

    Chance 是一个基于 JavaScript 的随机数工具类.可以生成随机数字,名称,地址,域名,邮箱,时间等等,几乎网站中使用的任何形式的内容都能够生成.这个随机数工具可以帮助减少单调的测试数据编 ...

  2. poj 1698 Alice‘s Chance

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

  3. 【性能诊断】九、并发场景的性能分析(windbg案例,Fist Chance Exception/Crash dump)

          经常会碰到这样的场景,自测及单单点的测试时没有任何问题,但在并发环境或生产环境下有时出现没规律的异常.报错等情况.在代码中增加日志是其中一种解决方式:抓取指定异常时的dump,通过wind ...

  4. (C# Debug)A first chance exception of type 'System.ArgumentException' occurred in System.Data.dll

    Debug 模式下运行程序的时候,Output 窗口出来个错误“A first chance exception of type 'System.ArgumentException' occurred ...

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

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

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

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

  7. You can fail at what you don't want, so you might as well take a chance on doing what you love.

    You can fail at what you don't want, so you might as well take a chance on doing what you love. 做不想做 ...

  8. Opportunity的chance of success的赋值逻辑

    该字段的值和另外两个字段Sales Stage和Status都相关. 从下列function module CRM_OPPORT_H_PROB_SET_EC可看出,当status不为代码中的这些硬编码 ...

  9. 理解First Chance和Second Chance避免单步调试

    原文链接地址:http://blog.csdn.net/Donjuan/article/details/3859160 在现在C++.Java..Net代码大行其道的时候,很多代码错误(Bug)都是通 ...

随机推荐

  1. Largest Rectangle in a Histogram(最大矩形面积,动态规划思想)

    Largest Rectangle in a Histogram Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 ...

  2. 用纯jsp实现用户的登录、注册与退出

    用户的登录.注册和退出是一个系统最常见的功能,现将各功能用jsp代码表示出来 用户的登录: 其中connDB是数据库连接类,将用户名username放入session中 <%@ page con ...

  3. swift论坛正式上线

    www.iswifting.com swift论坛正式上线.有问答专区,也有技术分享区,还有学习资料区,大家一起学习成长! 2014中国互联网大会于8月26日开幕. 政府主管部门.行业专家.企业领袖将 ...

  4. JS学习笔记(三)函数

    js中的方法名一般都是首字母小写,其余单词首字母大写的规范. 声明 function 函数名(参数列表) { // 函数体 return 返回值; } 调用 函数名(); (js中花括号喜欢用这种方式 ...

  5. 权威指南之脚本化jquery

    jqury函数 jquery()($())有4种不同的调用方式 第一种是最常用的调用方式是传递css选择器(字符串)给$()方法.当通过这种方式调用时,$()方法会返回当前文档中匹配该选择器的元素集. ...

  6. Hadoop学习之自定义二次排序

    一.概述    MapReduce框架对处理结果的输出会根据key值进行默认的排序,这个默认排序可以满足一部分需求,但是也是十分有限的.在我们实际的需求当中,往 往有要对reduce输出结果进行二次排 ...

  7. 怎样使用Markdown

    转自:http://wowubuntu.com/markdown/basic.html 段落.标题.区块代码 一个段落是由一个以上的连接的行句组成,而一个以上的空行则会划分出不同的段落(空行的定义是显 ...

  8. TextView settextcolor 无效解决方案

    viHolder.order_item_tipcolor.setBackgroundColor(context .getResources().getColor(R.color.order_xixie ...

  9. 一次U盘安装Ubuntu双系统实录

    准备:Win7系统(原来就在我电脑的系统) UltraISO(把系统写进U盘的工具) EasyBCD(双系统引导修复工具) 笔记本电脑(我的是联想Y470N) U盘一个 步骤: U盘准备工作: 插入U ...

  10. 移动端的click

    移动端的click 移动端click和touch的关系 搬运 http://segmentfault.com/q/1010000000691822 手指在屏幕上滑动时 各个touch的触发顺序 tou ...