Poj1698 Alice's Chance

Source: Internet
Author: User

Time Limit: 1000 MS Memory Limit: 10000 KTotal Submissions: 4472 Accepted: 1884 DescriptionAlice, 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 Ny of them !! You are asked to tell her whether she can act in all the films. as for a film, it will be made ONLY on some fixed days in a week, I. e ., alice can only work for the film on these days; Alice shocould work for it at least for specified number of days; the film MUST be finished before a prearranged deadline. for example, assuming a film can be made only on Monday, Wednesday and Saturday; Alice shocould w Ork 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. inputThe first line of the input contains a single integer T (1 <= T <= 20), the number of test cases. then T case S 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 shoshould go to the film for D days and the film must be finished in W weeks. outputFor each test case print a single line, 'yes' if Alice can attend all the films, otherwise 'no '. sample Input220 1 0 1 0 1 0 9 30 1 1 1 0 0 0 6 420 1 0 1 0 1 0 9 40 1 1 1 0 0 0 6 2 Sample OutputYesNoHintA proper schedule for first test case: date Sun Mon Tue Wed Th U Fri Sat week1 film1 film2 film1 film1 week2 film1 film2 film1 film1 week3 film1 film2 film1 film1 week4 film2 film2 1_monthly -- 2004.07.18 the biggest stream is regarded as 0 as the source point, consider "371" as the end point, 1-351 days, as the center point. In this way, from 0 to 357-, a line is connected to an edge with d traffic, when the number of days and the end point are connected to one side, the last run will be done, and the maximum flow calculation error will be done!

#include <iostream>  #include <string.h>  #include <stdio.h>  using namespace std;  #define E 20000  #define N 400  #define typec int  const typec inf=0x3f3f3f3f;  int day[N][10];  struct edge{int x,y,nxt;typec c;}bf[E];  int ne,head[N],cur[N],ps[N],dep[N];  void addedge(int x,int y,typec c)  {      bf[ne].x=x;bf[ne].y=y;bf[ne].c=c;      bf[ne].nxt=head[x];head[x]=ne++;      bf[ne].x=y;bf[ne].y=x;bf[ne].c=0;      bf[ne].nxt=head[y];head[y]=ne++;  }  typec flow(int n,int s,int t)  {      typec  tr,res=0;      int i,j,k,f,r,top;      while(1)      {          memset(dep,-1,n*sizeof(int));          for(f=dep[ps[0]=s]=0,r=1;f!=r;)          {              for(i=ps[f++],j=head[i];j;j=bf[j].nxt)              {                  if(bf[j].c&&-1==dep[k=bf[j].y])                  {                      dep[k]=dep[i]+1;ps[r++]=k;                      if(k==t){f=r;break;}                  }              }          }              if(-1==dep[t])break;              memcpy(cur,head,n*sizeof(int));              for(i=s,top=0;;)              {                  if(i==t)                  {                      for(k=0,tr=inf;k<top;k++)                      {                          if(bf[ps[k]].c<tr)                          tr=bf[ps[f=k]].c;                      }                      for(k=0;k<top;++k)                      {                          bf[ps[k]].c-=tr,bf[ps[k]^1].c+=tr;                      }                      res+=tr;i=bf[ps[top=f]].x;                  }                  for(j=cur[i];cur[i];j=cur[i]=bf[cur[i]].nxt)                  if(bf[j].c&&dep[i]+1==dep[bf[j].y])break;                  if(cur[i])                  {                      ps[top++]=cur[i];i=bf[cur[i]].y;                  }                  else                  {                      if(0==top)break;                      dep[i]=-1;i=bf[ps[--top]].x;                  }              }      }      return res;  }  int main()  {      int tcase,n,s,i,j;      scanf("%d",&tcase);      while(tcase--)      {          ne=2;          memset(head,0,sizeof(head));          scanf("%d",&n);          s=0;          for(i=1;i<=350;i++)          {              addedge(i,371,1);          }          for(i=1;i<=n;i++)          {              for(j=0;j<9;j++)              {                  scanf("%d",&day[i][j]);              }              s+=day[i][7];              addedge(0,350+i,day[i][7]);              for(j=0;j<7;j++)              if(day[i][j])              {                 for(int k=1;k<=day[i][8];k++)                  addedge(350+i,7*(k-1)+j+1,1);              }          }          if(flow(372,0,371)==s)          printf("Yes\n");          else          printf("No\n");      }      return 0;  }  

 


Related Article

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.