【POJ - 1698】Alice's Chance(网络流最大流,建图)

题干:

Alice, a charming girl, have been dreaming of being a movie star for long. Her chances will come now, for several filmmaking companies invite her to play the chief role in their new films. Unfortunately, all these companies will start making the films at the same time, and the greedy Alice doesn't want to miss any of them!! You are asked to tell her whether she can act in all the films. 

As for a film, 

  1. it will be made ONLY on some fixed days in a week, i.e., Alice can only work for the film on these days; 
  2. Alice should work for it at least for specified number of days; 
  3. the film MUST be finished before a prearranged deadline.


For example, assuming a film can be made only on Monday, Wednesday and Saturday; Alice should work for the film at least for 4 days; and it must be finished within 3 weeks. In this case she can work for the film on Monday of the first week, on Monday and Saturday of the second week, and on Monday of the third week. 

Notice that on a single day Alice can work on at most ONE film. 

Input

The first line of the input contains a single integer T (1 <= T <= 20), the number of test cases. Then T cases follow. Each test case begins with a single line containing an integer N (1 <= N <= 20), the number of films. Each of the following n lines is in the form of "F1 F2 F3 F4 F5 F6 F7 D W". Fi (1 <= i <= 7) is 1 or 0, representing whether the film can be made on the i-th day in a week (a week starts on Sunday): 1 means that the film can be made on this day, while 0 means the opposite. Both D (1 <= D <= 50) and W (1 <= W <= 50) are integers, and Alice should go to the film for D days and the film must be finished in W weeks.

Output

For each test case print a single line, 'Yes' if Alice can attend all the films, otherwise 'No'.

Sample Input

2
2
0 1 0 1 0 1 0 9 3
0 1 1 1 0 0 0 6 4
2
0 1 0 1 0 1 0 9 4
0 1 1 1 0 0 0 6 2

Sample Output

Yes
No

Hint

A proper schedule for the first test case:date     Sun    Mon    Tue    Wed    Thu    Fri    Satweek1          film1  film2  film1         film1week2          film1  film2  film1         film1week3          film1  film2  film1         film1week4          film2  film2  film2

题目大意:

alice接了N部电影的拍摄工作,所有电影在同一天开工。对于每个电影来说(第i个),每周只有固定几天拍,且必须在W_i周内拍完,alice至少需要去拍D_i天。问alice能否完成所有电影拍摄。alice每天只能去拍一部电影。

解题报告:

将电影也看做节点,将每一天看做一个节点,因为最多50周,所以最多350个节点。从源点出发流向每部电影,流量就是需要拍摄的天数,从每部电影到拍摄周内拍摄的那些天,流量是1,因为每天只能拍一部,同理这些天都连接到汇点,流量也是1,然后看源点能否满流就可以了。

AC代码:

#include<cstring>
#include<cstdio>
#include<algorithm>
#include<iostream>
using namespace std;
int tot;
struct Edge {int to,ne,w;
} e[100005 * 2];
int head[10005];
int st,ed;
int dis[10050],q[10005];//一共多少个点跑bfs,dis数组和q数组就开多大。 
void add(int u,int v,int w) {e[++tot].to=v; e[tot].w=w; e[tot].ne=head[u]; head[u]=tot;e[++tot].to=u; e[tot].w=0; e[tot].ne=head[v]; head[v]=tot;
}
bool bfs(int st,int ed) {memset(dis,-1,sizeof(dis));int front=0,tail=0;q[tail++]=st;dis[st]=0;while(front<tail) {int cur = q[front];if(cur == ed) return 1;front++;for(int i = head[cur]; i!=-1; i = e[i].ne) {if(e[i].w&&dis[e[i].to]<0) {q[tail++]=e[i].to;dis[e[i].to]=dis[cur]+1;}}}if(dis[ed]==-1) return 0;return 1;
}
int dfs(int cur,int limit) {//limit为源点到这个点的路径上的最小边权 if(limit==0||cur==ed) return limit;int w,flow=0;for(int i = head[cur]; i!=-1; i = e[i].ne) {		if(e[i].w&&dis[e[i].to]==dis[cur]+1) {w=dfs(e[i].to,min(limit,e[i].w));e[i].w-=w;e[i^1].w+=w;flow+=w;limit-=w;if(limit==0) break;}}if(!flow) dis[cur]=-1;return flow;
}
int dinic() {int ans = 0;while(bfs(st,ed)) ans+=dfs(st,0x7fffffff);return ans;
}
int a[100005];
int main()
{int t,n;cin>>t;while(t--) {tot=1;memset(head,-1,sizeof head);scanf("%d",&n);st=2000,ed=2001;//自己定就行了 for(int i = 101; i<=500; i++) /*add(i,i+1000,1),*/add(i,ed,1);//让每一天的拆点连起来,并且把后置点和ed连起来 //其实上一步是不需要拆点的,因为每个点和终点只有一个连边,所以不需要控制这个点只能被选择一次。 但是拆不拆点都可以过。int ans = 0;for(int i = 1; i<=n; i++) {for(int j = 1; j<=9; j++) scanf("%d",a+j);add(st,i,a[8]);//我要给这个电影提供a[8]这么多天的流量。 ans += a[8];for(int j = 1; j<=7; j++) {if(a[j] == 0) continue;for(int k = 0; k<a[9]; k++) {//k=1,k<a[9]也可以? add(i,100+7*k+j,1);}}}int out = dinic();if(ans == out) printf("Yes\n");else printf("No\n");		}return 0 ;
}

 

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/440016.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

由浅到深理解ROS URDF教程

创建自己的URDF文件 1.1创建树形结构文件 在这部分教程中要创建的将是下面的图形所描述的机器人的urdf文件 图片中这个机器人是一个树形结构的。让我们开始非常简单的创建这个树型结构的描述文件&#xff0c;不用担心维度等的问题。创建一个my_robot.urdf文件&#xff0c;内容如…

wireshark基本使用及介绍

Wireshark使用 注&#xff1a;本文中使用的wireshark是3.2.2版本 捕获过滤器表达式 下面是常用的捕获过滤器&#xff0c;wireshark中&#xff1a;捕获->捕获过滤器 除此外&#xff0c;还可以指明传输方向&#xff0c;如&#xff1a;src&#xff08;源方向&#xff09;, …

1.2)深度学习笔记------神经网络的编程基础

目录 1&#xff09;Binary Classification 2&#xff09;Logistic Regression 3&#xff09;Logistic Regression Cost Function 4&#xff09;Gradient Descent 5&#xff09;Logistic Regression Gradient Descent&#xff08;重点&#xff09; 6&#xff09;Gradient …

CS231n Convolutional Neural Networks for Visual Recognition------Python Tutorial

源链接为&#xff1a;http://cs231n.github.io/python-numpy-tutorial/。 这篇指导书是由Justin Johnson编写的。 在这门课程中我们将使用Python语言完成所有变成任务&#xff01;Python本身就是一种很棒的通用编程语言&#xff0c;但是在一些流行的库帮助下&#xff08;numpy&…

【HDU - 3081】Marriage Match II(网络流最大流,二分+网络流)

题干&#xff1a; Presumably, you all have known the question of stable marriage match. A girl will choose a boy; it is similar as the game of playing house we used to play when we are kids. What a happy time as so many friends playing together. And it is …

IP、TCP、UDP、HTTP头部信息

IP头部信息 ip报文段格式 版本&#xff1a; 占4位&#xff0c;表明IP协议实现的版本号&#xff0c;当前一般为IPv4&#xff0c;即0100。报头长度 &#xff1a; 占4位&#xff0c;因为头部长度不固定&#xff08;Option可选部分不固定&#xff09;&#xff0c;所以需要标识…

ROS技术点滴 —— MoveIt!中的运动学插件

MoveIt!是ROS中一个重要的集成化开发平台&#xff0c;由一系列移动操作的功能包组成&#xff0c;提供运动规划、操作控制、3D感知、运动学等功能模块&#xff0c;是ROS社区中使用度排名前三的功能包&#xff0c;目前已经支持众多机器人硬件平台。 MoveIt!中的众多功能都使用插件…

1)机器学习基石笔记Lecture1:The Learning Problem

网上关于机器学习的课程有很多&#xff0c;其中最著名的是吴恩达老师的课程&#xff0c;最近又发现了NTU林轩田老师的《机器学习基石》课程&#xff0c;这门课也很好。课程总共分为4部分&#xff0c;总共分为16节课&#xff0c;今天来记录第一节课。 When Can Machines Learn?…

MMS协议

MMS格式解析 简介&#xff1a; MMS是微软的私有流媒体协议。 它的最初目的是通过网络传输多媒体广播、视频、音轨、现场直播和一系列的实时或实况材料。 MMS建立在UDP或TCP传输&#xff0f;网络层上&#xff0c;是属于应用层的。使用TCP的MMS上URL是MMS://或者MMST://&#x…

【HDU - 6118】度度熊的交易计划(最小费用可行流,网络流费用流变形 )

题干&#xff1a; 度度熊参与了喵哈哈村的商业大会&#xff0c;但是这次商业大会遇到了一个难题&#xff1a; 喵哈哈村以及周围的村庄可以看做是一共由n个片区&#xff0c;m条公路组成的地区。 由于生产能力的区别&#xff0c;第i个片区能够花费a[i]元生产1个商品&#xff0…

老王说ros的tf库

ros的tf库 为了这个题目&#xff0c;我是拿出了挤沟的精神挤时间&#xff0c;是下了功夫的&#xff0c;线性代数、矩阵论复习了&#xff0c;惯性导航里的dcm、四元数也了解了&#xff0c;刚体力学也翻了&#xff0c;wiki里的欧拉角也读了&#xff0c;tf的tutorial、paper、sou…

Apollo进阶课程 ③ | 开源模块讲解(中)

目录 1&#xff09;ISO-26262概述 2&#xff09;ISO-26262认证流程 3&#xff09;ISO-26262优点与缺陷 原文链接&#xff1a;Apollo进阶课程 ③ | 开源模块讲解&#xff08;中&#xff09; Apollo自动驾驶进阶课程是由百度Apollo联合北京大学共同开设的课程&#xff0c;邀请…

python 问题集

打开文件是报&#xff1a;UnicodeDecodeError: ‘utf-8’ codec can’t decode byte 0xe9 in position 0: unexpected end of data UnicodeDecodeError:“utf-8”编解码器无法解码位置0中的字节0xe9:unex 在open中加入encodingunicode_escape 如&#xff1a; with open(file_n…

【HDU - 6447】YJJ's Salesman(降维dp,树状数组优化dp)

题干&#xff1a; YJJ is a salesman who has traveled through western country. YJJ is always on journey. Either is he at the destination, or on the way to destination. One day, he is going to travel from city A to southeastern city B. Let us assume that A …

由浅到深理解ROS(5.1)- roslaunch 学习

oslaunch 用处&#xff1a;将多个rosnode 结合起来&#xff0c;一起运行。这样就不需要一个个的运行。 roslaunch格式 &#xff08;add_two.launch&#xff09; <launch> <arg name"a" default"1" /> <arg name"b&q…

CS231n Convolutional Neural Networks for Visual Recognition------Numpy Tutorial

源链接为&#xff1a;http://cs231n.github.io/python-numpy-tutorial/。 这篇指导书是由Justin Johnson编写的。 在这门课程中我们将使用Python语言完成所有变成任务&#xff01;Python本身就是一种很棒的通用编程语言&#xff0c;但是在一些流行的库帮助下&#xff08;numpy&…

【CodeForces - 1047C】Enlarge GCD(数学,枚举,预处理打表,思维)

题干&#xff1a; F先生有n个正整数&#xff0c;a1&#xff0c;a2&#xff0c;...&#xff0c;an 他认为这些整数的最大公约数太小了,所以他想通过删除一些整数来扩大它 您的任务是计算需要删除的最小整数数,以便剩余整数的最大公约数大于所有整数的公约数. Input 3 1 2 4…

TS解析文档

TS格式解析 简介&#xff1a; ts文件为传输流文件&#xff0c;视频编码主要格式h264/mpeg4&#xff0c;音频为acc/MP3。 ts的包是一个一个188字节的包组成&#xff0c;这188字节里面由一个0x47开头的包作为同步。 也就是说&#xff0c;如果你找到了0x47&#xff0c;如果与它相…

ROS入门之——浅谈launch

0.何为launch&#xff1f; launch&#xff0c;中文含义是启动&#xff0c;launch文件顾名思义就是启动文件&#xff0c;要说这launch文件啊&#xff0c;那还得从roslaunch说起。 相传&#xff0c;在程序猿们还没有使用roslaunch之前&#xff0c;需要手动rosrun逐个启动node&am…

2)机器学习基石笔记Lecture2:Learning to Answer Yes/No

目录 0.上节回顾 1. Perceptron Hypothesis Set 2. Perceptron Learning Algorithm(PLA)&#xff08;重点&#xff09; 3. Guarantee of PLA&#xff08;难点&#xff09; 4. Non-Separable Data 0.上节回顾 第一节课主要讲述了机器学习的定义及机器学习的过程&#xff0…