标签:show images onclick return nbsp clear code color click
BZOJ 1028
暴力枚举听的那张牌,和那个多余的两张牌,其余的mod3后模拟就可以了
1 #include <cstdio> 2 const int Maxn=510; 3 int n,m,a[Maxn],b[Maxn],cnt,Ans[Maxn],x; 4 bool Check() 5 { 6 for (int i=1;i<=n;i++) 7 if (a[i]>=2) 8 { 9 for (int j=1;j<=n+2;j++) b[j]=a[j]; 10 b[i]-=2; bool flag=true; 11 for (int j=1;j<=n;j++) 12 if (b[j]) 13 { 14 if (b[j]<0) {flag=false; break;} 15 int t=b[j]%3; 16 b[j+1]-=t,b[j+2]-=t; 17 } 18 if (!flag || b[n+1]<0 || b[n+2]<0) continue; 19 return true; 20 } 21 return false; 22 } 23 24 int main() 25 { 26 scanf("%d%d",&n,&m); 27 for (int i=1;i<=3*m+1;i++) scanf("%d",&x),a[x]++; 28 for (int i=1;i<=n;i++) 29 { 30 a[i]++; 31 if (Check()) Ans[++cnt]=i; 32 a[i]--; 33 } 34 if (cnt==0) {puts("NO"); return 0;} 35 for (int i=1;i<cnt;i++) printf("%d ",Ans[i]); printf("%d\n",Ans[cnt]); 36 return 0; 37 }
BZOJ 1860
直接Dfs枚举方案数,然后用Hash判重就可以了,类似于斗地主
1 #include<cstdio> 2 #include<set> 3 #define LL long long 4 using namespace std; 5 const LL Mod=1000000000000000003; 6 set<LL>S; 7 LL KASE,Bin[105],a[105],Sum,mul=131ll; 8 inline bool Dfs(LL k,bool two,LL Sta) 9 { 10 if (S.find(Sta)!=S.end()) return 0; 11 S.insert(Sta); 12 while (!a[k]&&k<=100) k++; 13 if (k==101) return two; 14 if (a[k]&&a[k+1]&&a[k+2]&&k<=98) 15 { 16 a[k]--;a[k+1]--;a[k+2]--; 17 if (Dfs(k,two,(Sta-Bin[k]-Bin[k+1]-Bin[k+2]+3*Mod)%Mod)) return true; 18 a[k]++;a[k+1]++;a[k+2]++; 19 } 20 if (a[k]>=4) 21 { 22 a[k]-=4; 23 if (Dfs(k,two,(Sta-Bin[k]*4+4*Mod)%Mod)) return true; 24 a[k]+=4; 25 } 26 if (a[k]>=3) 27 { 28 a[k]-=3; 29 if (Dfs(k,two,(Sta-Bin[k]*3+3*Mod)%Mod)) return true; 30 a[k]+=3; 31 } 32 if (a[k]>=2&&!two) 33 { 34 a[k]-=2; 35 if (Dfs(k,1,(Sta-Bin[k]*2-Bin[100]+3*Mod)%Mod)) return true; 36 a[k]+=2; 37 } 38 return false; 39 } 40 int main() 41 { 42 Bin[1]=1; for (int i=2;i<=100;i++) Bin[i]=(Bin[i-1]*mul)%Mod; 43 scanf("%d",&KASE); 44 for (int Kase=1;Kase<=KASE;Kase++) 45 { 46 Sum=0; 47 for (int i=1;i<=100;i++) scanf("%lld",&a[i]),Sum=(Sum+Bin[i]*a[i])%Mod; 48 S.clear(); 49 if (Dfs(1,0,Sum)) puts("Yes"); else puts("No"); 50 } 51 return 0; 52 }
标签:show images onclick return nbsp clear code color click
原文地址:http://www.cnblogs.com/yyjxx2010xyu/p/6049368.html