省選專練之【PKUSC2018】主鬥地
阿新 • • 發佈:2018-11-02
額很清新的一道題
實際上這道題沒有坊間傳的那麼難吧。。。
你仔細觀察會發現如下性質:
對子沒有單牌優(這個好理解如果對子被壓就是單牌被壓兩次)
飛機沒有三帶X優
順子這些更不能出
於是惟一的不確定性在於打幾個三帶X和四帶二
這個可以暴力列舉(冷靜思考牌堆裡面是不可能有很多這種牌的)
然後是Check的時候三帶幾也要暴力列舉(這也是很少的不超過6次)
然後暴力列舉jiry手中的牌
放進去check就好了
#include<bits/stdc++.h> using namespace std; int A[14];//A 's card int B[14];//The card remain int C[14];//B 's card char S[18]; int Code(char C){ if('4'<=C&&C<='9')return C-'4'; if(C=='T')return 6; if(C=='J')return 7; if(C=='Q')return 8; if(C=='K')return 9; if(C=='A')return 10; if(C=='2')return 11; if(C=='w')return 12; if(C=='W')return 13; } int Ans=0,AT,BT; int E[14]; int F[14]; bool Check_Single(int cntS,int cntP){/*Now We Have cntS cards to puts one single card or a double same card and cntP cards to puts two single cards*/ for(int i=0;i<=cntS;++i){ int p=i; int q=cntP*2+cntS-i; memcpy(E,C,sizeof(C)); for(int j=13;j>=0;--j){ while(p&&E[j]>=2)E[j]-=2,p--; while(q&&E[j])E[j]--,q--; } if(p||q)continue;//here is two little single cards p=i; q=cntP*2+cntS-i; memcpy(F,A,sizeof(A)); for(int j=0;j<=13;++j){ while(p&&F[j]>=2)F[j]-=2,p--; while(q&&F[j])F[j]--,q--; } if(p||q)continue; p=0; int flag=1; for(int j=0;j<=13;++j){ if(F[j]>p)flag=0; p-=F[j]; p+=E[j]; } if(flag)return 1; } return 0; } bool Check_Plane(int now,int cntS/*3-1*/,int cntP/*4-2*/,int Suse/*S-back*/,int Puse/*P-back*/){/*p means four cards with two cards*//*S means three cards with one cards*/ // if(AT<cntS)return 0; // if(BT<cntP)return 0; if(now==14){ if((!Suse)&&(!Puse))return Check_Single(cntS,cntP); else return 0; } bool Goal=0; if(C[now]>=4){ C[now]-=4; Goal=Check_Plane(now+1,cntS,cntP+1,Suse,Puse+1); C[now]+=4; if(Goal)return Goal; } if(C[now]>=3){ C[now]-=3; Goal=Check_Plane(now+1,cntS+1,cntP,Suse+1,Puse); C[now]+=3; if(Goal)return Goal; } if(A[now]>=4&&Puse){ A[now]-=4; Goal=Check_Plane(now+1,cntS,cntP,Suse,Puse-1); A[now]+=4; if(Goal)return Goal; } if(A[now]>=3&&Suse){ A[now]-=3; Goal=Check_Plane(now+1,cntS,cntP,Suse-1,Puse); A[now]+=3; if(Goal)return Goal; } Check_Plane(now+1,cntS,cntP,Suse,Puse); } void DFS(int now,int ret){ if(ret<0)return; if(now==14){ if(ret==0&&Check_Plane(0,0,0,0,0)){ Ans++; } return; } for(int i=0;i<=min(B[now],ret);++i){ C[now]=i; DFS(now+1,ret-i); C[now]=0; } } int main(){ while(~scanf("%s",S)){ memset(C,0,sizeof(C)); memset(A,0,sizeof(A)); memset(B,0,sizeof(B)); Ans=0; AT=0; BT=0; for(int i=0;i<12;++i)B[i]=4; B[12]=1; B[13]=1; for(int i=0;i<12;++i)AT+=(A[i]>=3),BT+=(B[i]>=3); for(int i=0;i<17;++i){ int x=Code(S[i]); ++A[x]; --B[x]; } DFS(0,17); cout<<Ans<<'\n'; } }