poj 1698 Alice's Chance SAP 最大流

【题意】:Alice有n部电影要拍,规定爱丽丝每部电影在每个礼拜只有固定的几天可以拍电影,只可以拍前面w个礼拜,并且这部电影要拍d天,问爱丽丝能不能拍完所有的电影

【建图】:源点与每部电影连边,容量为天数,每部电影与可以拍该电影的那些天数连边,容量为1,再所有的天数与汇点连边容量为1。 要注意天数和汇点连边的时候不要重复了,我这里用的数组不会出现这种情况。

 1 #include<iostream>
 2 #include<vector>
 3 #include<cstring>
 4 #include<queue>
 5 #include<cstdio>
 6 using namespace std;
 7 #define maxx 400
 8 #define INF 9999999
 9
10 int c[maxx][maxx],f[maxx][maxx],p[maxx], a[maxx];
11
12 void add(int u,int v,int w)
13 {
14     c[u][v]=w;
15
16 }
17
18 int maxflow(int s,int t,int n)
19 {
20     queue<int> q;
21     memset(f,0,sizeof(f));
22     int flow=0;
23     while(1)
24     {
25         memset(a,0,sizeof(a));
26         a[s] = INF;
27         q.push(s);
28
29         while(!q.empty())
30         {
31             int u = q.front();
32             q.pop();
33             for(int v = 1; v <= n; v++) if(!a[v] && c[u][v] > f[u][v])
34                 {
35                     p[v] = u;
36                     q.push(v);
37                     a[v] = min(a[u], c[u][v]-f[u][v]);
38                 }
39         }
40
41         if(a[t] == 0)
42             break;
43         for(int u = t; u != s; u = p[u])
44         {
45             f[p[u]][u] += a[t];
46             f[u][p[u]] -= a[t];
47         }
48         flow += a[t];
49     }
50     return flow;
51 }
52
53 int main()
54 {
55     int cnt,n;
56     scanf("%d",&cnt);
57     while(cnt--)
58     {
59         scanf("%d",&n);
60         memset(c,0,sizeof(c));
61         int ok[10],day,week,tt=371,tot=0;
62         for(int i=1; i<=n; i++)
63         {
64             for(int j=0; j<7; j++)
65                 scanf("%d",&ok[j]);
66             scanf("%d%d",&day,&week);
67             tot+=day;
68             add(0,i,day);
69             for(int j=0; j<week; j++)
70                 for(int k=0; k<7; k++)
71                 {
72                     if(ok[k])
73                        add(i,j*7+k+n+1,1);
74                     add(j*7+k+n+1,tt,1);
75                 }
76         }
77         int flow;
78         flow=maxflow(0,tt,tt);
79         //printf("flow  %d\n",flow);
80         if(tot==flow)
81             printf("Yes\n");
82         else printf("No\n");
83     }
84     return 0;
85 }

poj 1698 Alice's Chance SAP 最大流

时间: 2024-08-04 22:21:05

poj 1698 Alice's Chance SAP 最大流的相关文章

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

POJ 1698 Alice's Chance 题目链接 题意:拍n部电影,每部电影要在前w星期完成,并且一周只有一些天是可以拍的,每部电影有个需要的总时间,问是否能拍完电影 思路:源点向每部电影连边,容量为d,然后每部电影对应能拍的那天连边,由于每天容量限制是1,所以进行拆点,然后连向汇点即可 代码: #include <cstdio> #include <cstring> #include <queue> #include <algorithm> usi

poj 1698 Alice&#39;s Chance 拆点最大流

将星期拆点,符合条件的连边,最后统计汇点流量是否满就行了,注意结点编号. #include<cstdio> #include<cstring> #include<cmath> #include<iostream> #include<algorithm> #include<set> #include<map> #include<queue> #include<vector> #include<s

POJ 1698 Alice&#39;s Chance(网络流之最大流)

题目地址:POJ 1698 水题..将每部电影与它可以演的那一天连边就行了.建二分图.用二分最大匹配也完全可以做. 代码如下: #include <iostream> #include <cstdio> #include <string> #include <cstring> #include <stdlib.h> #include <math.h> #include <ctype.h> #include <queu

poj 1698 Alice&#39;s Chance(网络流)

Alice's Chance Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 5280   Accepted: 2171 Description Alice, a charming girl, have been dreaming of being a movie star for long. Her chances will come now, for several filmmaking companies invit

POJ 1698 Alice&#39;s Chance 网络流(水

题目链接:点击打开链接 题目大意:   有个人想拍n部电影,每部电影限定每周哪几天可以拍 并且必须在第ki周之前把这部电影拍完,问能否拍完n部电影 解题思路:  把每部电影当作一个顶点,源点指向这些顶点,容量为该电影需要拍多少天 然后把每一天都当作顶点,某个工作可以在这天完成就连容量为1大边 每天的顶点指向汇点,容量也为1 最后求出最大流,满流则说明可以完成这些工作 啦啦啦 #include <cstdio> #include <cstring> #include <algo

poj 1698 Alice&#39;s Chance 二分图多重匹配

题意: 一个演员要拍n部电影,每部电影只能在一周的特定几天拍(如周2,周4,周5),第i部电影要拍di天,必须要在wi周拍完,问演员是否可以完成任务. 分析: 建二分图,转化为二分图的多重匹配. 代码: //poj 1698 //sep9 #include <iostream> using namespace std; const int maxX=64*7; const int maxY=64; int g[maxX][maxY],match[maxY][maxX]; int vis[max

POJ 1698 Alice&#39;s Chance(网络流+构图)

题目链接:http://poj.org/problem?id=1698 题目: Description 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. Unfortuna

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

POJ 1698 Alice's Chance 题目链接 题意:拍n部电影.每部电影要在前w星期完毕,而且一周仅仅有一些天是能够拍的,每部电影有个须要的总时间,问能否拍完电影 思路:源点向每部电影连边,容量为d,然后每部电影相应能拍的那天连边,因为每天容量限制是1.所以进行拆点,然后连向汇点就可以 代码: #include <cstdio> #include <cstring> #include <queue> #include <algorithm> us

【POJ 1698】Alice&#39;s Chance(二分图多重匹配)

http://poj.org/problem?id=1698 电影和日子匹配,电影可以匹配多个日子. 最多有maxw*7个日子. 二分图多重匹配完,检查一下是否每个电影都匹配了要求的日子那么多. #include<cstdio> #include<cstring> #include<algorithm> #define N 360 #define M 30 using namespace std; int t,n,m; int g[N][M]; int linker[M