码迷,mamicode.com
首页 > 其他好文 > 详细

poj 1698 Alice's Chance SAP 最大流

时间:2014-08-31 16:59:21      阅读:175      评论:0      收藏:0      [点我收藏+]

标签:style   blog   color   os   io   for   div   log   sp   

【题意】: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 最大流

标签:style   blog   color   os   io   for   div   log   sp   

原文地址:http://www.cnblogs.com/assult/p/3947757.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!