https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=2151
题意:给你十三张麻将,问你需要哪几张牌就可以胡牌,这个胡牌排除了七小对以及十三幺
胡牌必须要有一个对子加n个顺子或者三张相同的牌(n)可以为0
思路:枚举每一张牌,然后dfs一下看看是否可以胡
dfs我的是枚举每一个对子
1 #include <stdio.h> 2 #include <string.h> 3 #include <string> 4 #include <map> 5 #include <iostream> 6 using namespace std; 7 8 map<string,int>s; 9 10 string tmp[50]={"0","1S","2S","3S","4S","5S","6S","7S","8S","9S", 11 "0","1T","2T","3T","4T","5T","6T","7T","8T","9T", 12 "0","1W","2W","3W","4W","5W","6W","7W","8W","9W", 13 "0","DONG","NAN","XI","BEI","ZHONG","FA","BAI"}; 14 bool vis[56]; 15 int num[60]; 16 17 bool dfs(int cnt) 18 { 19 for(int i = 1;i<=37;i++) 20 { 21 if(num[i]>=3) 22 { 23 if(cnt==3) 24 return true; 25 num[i]-=3; 26 if(dfs(cnt+1)) 27 return true; 28 num[i]+=3; 29 } 30 } 31 for(int i = 1;i<=27;i++) 32 { 33 if(i%10!=8&&i%10!=9&&i%10!=0&&num[i]&&num[i+1]&&num[i+2]) 34 { 35 if(cnt==3) return true; 36 num[i]--; 37 num[i+1]--; 38 num[i+2]--; 39 if(dfs(cnt+1)) return true; 40 num[i]++; 41 num[i+1]++; 42 num[i+2]++; 43 } 44 } 45 return false; 46 } 47 48 bool check() 49 { 50 for(int i = 1;i<=37;i++) 51 { 52 if(num[i]>=2) 53 { 54 num[i]-=2; 55 if(dfs(0)) return true; 56 num[i]+=2; 57 } 58 } 59 return false; 60 } 61 62 63 int main() 64 { 65 // freopen("in.txt","r",stdin); 66 int Case = 0; 67 for(int i = 0;i<=37;i++) 68 s[tmp[i]] = i; 69 string str[20]; 70 while(cin>>str[1]){ 71 int cnt = 0; 72 memset(vis,false,sizeof(vis)); 73 memset(num,0,sizeof(num)); 74 if(str[1] == "0") break; 75 for(int i =2;i<=13;i++) cin>>str[i]; 76 77 for(int i = 1;i<=37;i++){ 78 memset(num,0,sizeof(num)); 79 for(int i = 1;i<=13;i++) 80 num[s[str[i]]]++; 81 if(i%10!=0&&num[i]!=4){ 82 num[i]++; 83 if(check()) 84 vis[i] = true,cnt++; 85 num[i]--; 86 } 87 } 88 printf("Case %d:",++Case); 89 90 for(int i = 1;i<=37;i++) 91 if(vis[i]) cout<<" "<<tmp[i]; 92 if(!cnt) 93 cout<<" Not ready"; 94 cout<<endl; 95 } 96 return 0; 97 }