Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 1608 | Accepted: 737 |
Description
Input
Output
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
#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;
}