#include <bits/stdc++.h> using namespace std; typedef long long LL; const int INF = 1<<12; const LL p = 99999; int dp[1234][1<<7],no[1234]; int mp[7][1234],n; int most[1234]; void input() { int c; memset(mp,0,sizeof(mp)); for(int i=0; i<7; i++) //input { scanf("%d",&c); for(int j=0; j<c; j++) { int x,y; char cc; scanf("%d%c",&x,&cc); if(cc!=32&&cc!=10) { scanf("%d",&y); mp[i][x]=1; for(int k=x+1; k<y; k++) mp[i][k]=2; mp[i][y]=-1; } else { mp[i][x]=1; } } } most[0]=0; for(int i=1;i<=n;i++) { int temp=0; for(int j=0;j<7;j++) { if(mp[j][i]>0) temp+=1<<j; } most[i]=temp;//最多需要这样的按键 } } int main() { int t,cas=1; scanf("%d",&t); while(t--) { scanf("%d",&n); input(); memset(no,0,sizeof(no)); int q; scanf("%d",&q); while(q--) { char s[10]; scanf("%s",s); int temp=0; for(int i=0; i<7; i++) { if(s[i]=='1') temp+=1<<i; } for(int i=0; i<1<<7; i++) { if((temp&i)==temp) no[i]=1; } } memset(dp,0,sizeof(dp)); for(int i=1; i<=n; i++) { for(int j=0; j<(1<<7); j++)//now { if((j&most[i])!=j) continue; if(no[j]) continue; for(int k=0; k<(1<<7); k++)//last { if((k&most[i-1])!=k) continue; if(no[k]) continue; int ans=0,flag=0; for(int w=0;w<7;w++) { if(mp[w][i]==1&&(j&(1<<w))) ans++; else if(mp[w][i]==2&&(j&(1<<w))&&(k&(1<<w))==0) flag=1; else if(mp[w][i]==-1&&(j&(1<<w))==0&&(k&(1<<w))) ans++; } if(!flag) { dp[i][j]=max(dp[i][j],dp[i-1][k]+ans); } } } } int out=0; for(int i=0;i<1<<7;i++) out=max(out,dp[n][i]); printf("Case #%d: %d\n",cas++,out); } return 0; } /* */ /* F:\temp\16139789.54806\Main.cc:2:25: error: bits/stdc++.h: No such file or directory F:\temp\16139789.54806\Main.cc: In function 'void input()': F:\temp\16139789.54806\Main.cc:13: error: 'memset' was not declared in this scope F:\temp\16139789.54806\Main.cc:16: error: 'scanf' was not declared in this scope F:\temp\16139789.54806\Main.cc: In function 'int main()': F:\temp\16139789.54806\Main.cc:51: error: 'scanf' was not declared in this scope F:\temp\16139789.54806\Main.cc:56: error: 'memset' was not declared in this scope F:\temp\16139789.54806\Main.cc:98: error: 'max' was not declared in this scope F:\temp\16139789.54806\Main.cc:105: error: 'max' was not declared in this scope F:\temp\16139789.54806\Main.cc:106: error: 'printf' was not declared in this scope */ |
Double click to view unformatted code.