POJ_1698_Alice's Chance
#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的更多相关文章
- Chance – 功能强大的 JavaScript 随机数生成类库
Chance 是一个基于 JavaScript 的随机数工具类.可以生成随机数字,名称,地址,域名,邮箱,时间等等,几乎网站中使用的任何形式的内容都能够生成.这个随机数工具可以帮助减少单调的测试数据编 ...
- poj 1698 Alice‘s Chance
poj 1698 Alice's Chance 题目地址: http://poj.org/problem?id=1698 题意: 演员Alice ,面对n场电影,每场电影拍摄持续w周,每周特定几天拍 ...
- 【性能诊断】九、并发场景的性能分析(windbg案例,Fist Chance Exception/Crash dump)
经常会碰到这样的场景,自测及单单点的测试时没有任何问题,但在并发环境或生产环境下有时出现没规律的异常.报错等情况.在代码中增加日志是其中一种解决方式:抓取指定异常时的dump,通过wind ...
- (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 ...
- Alice's Chance POJ - 1698(按时间点建边)
Alice's Chance Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 7791 Accepted: 3174 De ...
- 2018.07.06 POJ1698 Alice's Chance(最大流)
Alice's Chance Time Limit: 1000MS Memory Limit: 10000K Description Alice, a charming girl, have been ...
- 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. 做不想做 ...
- Opportunity的chance of success的赋值逻辑
该字段的值和另外两个字段Sales Stage和Status都相关. 从下列function module CRM_OPPORT_H_PROB_SET_EC可看出,当status不为代码中的这些硬编码 ...
- 理解First Chance和Second Chance避免单步调试
原文链接地址:http://blog.csdn.net/Donjuan/article/details/3859160 在现在C++.Java..Net代码大行其道的时候,很多代码错误(Bug)都是通 ...
随机推荐
- [虚拟化/云][全栈demo] 为qemu增加一个PCI的watchdog外设(二)
这篇文章的理解,需要一些专业知识了. 我们可以创建模拟自己的外设吗? 我们已经知道什么是qemu了,我们可以通过qmeu的提供的外设,DIY一个计算机了. 但是我们可能还不满足,我们可以自己制造一个外 ...
- Address already in use: JVM_Bind <null>:8080
解决方法: 1重开eclipse,端口号被占用,或者杀掉进程
- How many ways(记忆化搜索)
How many ways Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) To ...
- Android TXT文件读写
package com.wirelessqa.helper; import java.io.FileInputStream; import java.io.FileOutputStream; impo ...
- 框架计划随笔 三.EntityFramework在传统事务脚本模式下的使用
某个朋友问为什么不推首页或者允许评论,我说一直没怎么写博客,也习惯了先随便乱画再开始写文档,担心公开后一些不经意的"呓语“中得出的错误的结论会给别人错误的观点,所以这个系列只是当做熟悉写博客 ...
- jquery数字验证大小比较
$("#rewardForm").validate({ rules: { "reward": { ...
- jQuery的三种$()
参考脚本之家“http://www.jb51.net/article/21660.htm” $号是jQuery“类”的一个别称,$()构造了一个jQuery对象.所以,“$()”可以叫做jQuer ...
- BZOJ 3533: [Sdoi2014]向量集( 线段树 + 三分 )
答案一定是在凸壳上的(y>0上凸壳, y<0下凸壳). 线段树维护, 至多N次询问, 每次询问影响O(logN)数量级的线段树结点, 每个结点O(logN)暴力建凸壳, 然后O(logN) ...
- 创建一个ROS包
先前笔者不知道catkin到底是个什么东东,后来终于在官方网站上找到了答案,原来catkin是ROS的一个官方的编译构建系统,是原本的ROS的编译构建系统rosbuild的后继者.catkin的来源有 ...
- 小测试 php代理,nginx代理,直接访问对比
#php proxy total sent request num: 507 total handle read times: 506 506 fetches, 2 max parallel, 2.7 ...