标签:class efi turn 状压dp set c++ ace tput pen
地址:http://poj.openjudge.cn/practice/C17K/
题目:
There are N people living on Lying Island. Some of them are good guys, while others are bad.
It is known that good guys are always telling truths, while bad guys may be telling either truths or lies.
One day, an investigator came to Lying Island. He wondered how many good guys are there on the island. So he conducted an investigation.
People on the island are numbered from 1 to N. When the investigator was interviewing person i, he showed the islander the information about at most K people numbered from max{i-K,1} to (i-1).
Sometimes, the i-th islander would say, "Oh, person x is a good(bad) guy."
But sometimes, the i-th islander would mince his words, "Eh, if person x is a good(bad) guy, person y is a good(bad) guy."
Of course, x and y is less than i but no less than (i-K), because person i only saw the information of that at most K islanders.
The investigator does not think he can infer exactly how many good guys on the island from these words, but he feels that he can figure out how many good guys at most on the island. Can you help him?
2 7 2 Person 2: Person 1 is a good guy. Person 3: Person 2 is a bad guy. Person 4: If person 3 is a good guy, person 2 is a good guy. Person 5: If person 4 is a good guy, person 3 is a bad guy. Person 6: If person 5 is a bad guy, person 4 is a good guy. Person 7: If person 6 is a bad guy, person 5 is a bad guy. 7 4 Person 2: Person 1 is a bad guy. Person 3: Person 2 is a bad guy. Person 4: If person 3 is a good guy, person 1 is a bad guy. Person 5: Person 2 is a bad guy. Person 6: If person 4 is a good guy, person 2 is a bad guy. Person 7: Person 6 is a bad guy.
6 4
#include <bits/stdc++.h> using namespace std; #define MP make_pair #define PB push_back typedef long long LL; typedef pair<int,int> PII; const double eps=1e-8; const double pi=acos(-1.0); const int K=5e3+7; const int mod=1e9+7; int n,ans,k,dp[K][1<<10]; char sa[200]; int main(void) { int T; scanf("%d",&T); while(T--) { scanf("%d%d",&n,&k); memset(dp,-1,sizeof dp); for(int i=0,mx=(1<<9);i<mx;i++) dp[1][i]=0; for(int i=(1<<9),mx=(1<<10);i<mx;i++) dp[1][i]=1; for(int i=2,x,y,dx,dy;i<=n;i++) { scanf("%s%d%s%s",sa,&x,sa,sa); if(sa[0]==‘P‘) { scanf("%d%s%s%s",&x,sa,sa,sa); if(sa[0]==‘b‘) dx=0; else dx=1; gets(sa); for(int j=0,mx=1<<10;j<mx;j++) if(((j>>(x-i+10))&1)==dx&&~dp[i-1][j]) dp[i][(j+mx)>>1]=max(dp[i-1][j]+1,dp[i][(j+mx)>>1]); for(int j=0,mx=(1<<10);j<mx;j++) dp[i][j>>1]=max(dp[i][j>>1],dp[i-1][j]); } else { scanf("%s%d%s%s%s",sa,&x,sa,sa,sa); if(sa[0]==‘b‘) dx=0; else dx=1; scanf("%s%s%d%s%s%s",sa,sa,&y,sa,sa,sa); if(sa[0]==‘b‘) dy=0; else dy=1; gets(sa); for(int j=0,mx=1<<10;j<mx;j++) if(~dp[i-1][j] && !(((j>>(x-i+10))&1)==dx&&((j>>(y-i+10))&1)!=dy)) dp[i][(j+mx)>>1]=max(dp[i-1][j]+1,dp[i][(j+mx)>>1]); for(int j=0,mx=(1<<10);j<mx;j++) dp[i][j>>1]=max(dp[i-1][j],dp[i][j>>1]); } } ans=0; for(int i=0,mx=(1<<10);i<mx;i++) ans=max(ans,dp[n][i]); printf("%d\n",ans); } return 0; } /* Person 2: Person 1 is a bad guy. Person 3: Person 2 is a bad guy. Person 4: Person 3 is a bad guy. Person 5: Person 4 is a bad guy. Person 2: Person 1 is a good guy. Person 3: Person 2 is a good guy. Person 4: Person 3 is a bad guy. Person 5: Person 4 is a good guy. */
标签:class efi turn 状压dp set c++ ace tput pen
原文地址:http://www.cnblogs.com/weeping/p/7203505.html