额很清新的一道题
实际上这道题没有坊间传的那么难吧。。。
你仔细观察会发现如下性质:
对子没有单牌优(这个好理解如果对子被压就是单牌被压两次)
飞机没有三带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';
}
}