1698 Alice's Chance //MAXMATCH

Alice's Chance
Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 1608   Accepted: 737

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. 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 Sat
week1 film1 film2 film1 film1
week2 film1 film2 film1 film1
week3 film1 film2 film1 film1
week4 film2 film2 film2

Source

POJ Monthly--2004.07.18

 

 

#include<stdio.h>

#include<string.h>

const int INF=1<<28-1;

int mat[1100][400],link[400];

bool usedif[400];

int n,gx,gy;

bool can(int t)

{

    for(int i=1; i<=gy; i++)

    {

        if(usedif[i]==0&&mat[t][i]>0)

        {

            usedif[i]=1;

            if(link[i]==-1||can(link[i]))

            {

                link[i]=t;

                return true;

            }

        }

    }

    return false;

}

bool MaxMatch()

{

    memset(link,-1,sizeof(link));

    for(int i=1;i<=gx;i++)

    {

        memset(usedif,0,sizeof(usedif));

        if(!can(i))  return false;

    }

    return true;

}

 

int main()

{

    int T;

    scanf("%d",&T);

    while(T--)

    {

        scanf("%d",&n);

        gx=0;

        gy=0;

        memset(mat,0,sizeof(mat));

        for(int i=1;i<=n;i++)

        {

            int a1,a2,a3,a4,a5,a6,a7,d,w;

            scanf("%d%d%d%d%d%d%d%d%d",&a7,&a1,&a2,&a3,&a4,&a5,&a6,&d,&w);

            if(a7) { for(int k=1;k<=d;k++) for(int j=1;j<=w;j++) mat[k+gx][(j-1)*7+7]=1; }

            if(a6) { for(int k=1;k<=d;k++) for(int j=1;j<=w;j++) mat[k+gx][(j-1)*7+6]=1; }

            if(a5) { for(int k=1;k<=d;k++) for(int j=1;j<=w;j++) mat[k+gx][(j-1)*7+5]=1; }

            if(a4) { for(int k=1;k<=d;k++) for(int j=1;j<=w;j++) mat[k+gx][(j-1)*7+4]=1; }

            if(a3) { for(int k=1;k<=d;k++) for(int j=1;j<=w;j++) mat[k+gx][(j-1)*7+3]=1; }

            if(a2) { for(int k=1;k<=d;k++) for(int j=1;j<=w;j++) mat[k+gx][(j-1)*7+2]=1; }

            if(a1) { for(int k=1;k<=d;k++) for(int j=1;j<=w;j++) mat[k+gx][(j-1)*7+1]=1; }

            if(7*w>gy) gy=7*w;

            gx+=d;//1010

        }

        if(MaxMatch()) printf("Yes/n");

        else printf("No/n");

    }

    return 0;

}

你可能感兴趣的:(Date,Integer,input,sun,each,Go)