Poj 1698 Alice's chance sap Max stream

Source: Internet
Author: User

[Question]: Alice has n movies to make. It is required that Alice can make movies for only a fixed number of days each week. She can only take the first W weeks, and the movie will take D days. Ask Alice if she can finish all the movies.

[Graph]: The Source point is connected to each movie. The capacity is the number of days. Each movie is connected to the number of days that can be shot. The capacity is 1, in addition, the number of days connected to the settlement point is 1. Note that do not repeat the number of days and the number of links. The array I use here does not.

 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 Max stream

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.