1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<algorithm> 5 using namespace std; 6 const int maxn=27; 7 const int INF=0x7f7f7f7f; 8 int a[maxn],b[maxn],dp[maxn][maxn][maxn][maxn],cnt[maxn]; 9 int req[4]={0,5,3,2}; 10 bool fl[3]; 11 int t,n,ans,flag; 12 void dfs(int sum,int stp){ 13 cout<<sum<<" "<<stp<<endl; 14 if(stp==8) exit(0); 15 if(sum==0){ans=min(ans,stp);return;} 16 if(stp>=n) return; 17 //单顺子,双顺子,三顺子 18 for(int i=1;i<=3;i++){ 19 int l=1,r=0; 20 for(int j=1;j<=13;j++){ 21 if(cnt[j]>=i) r=i; 22 else l=i+1; 23 if(l-r+1>=req[i]){ 24 for(int k=l;k<=r;k++) cnt[k]-=i; 25 dfs(sum-(r-l+1)*i,stp+1); 26 for(int k=l;k<=r;k++) cnt[k]+=i; 27 } 28 } 29 } 30 //四带二 31 for(int i=1;i<=13;i++){ 32 for(int j=0;j<=13;j++){ 33 for(int k=0;k<=13;k++){ 34 if(cnt[i]>=4&&cnt[j]>=1&&cnt[k]>=1){ 35 cnt[i]-=4;cnt[j]--;cnt[k]--; 36 dfs(sum-6,stp+1); 37 cnt[i]+=4;cnt[j]++;cnt[k]++; 38 } 39 } 40 } 41 } 42 //三带二 43 for(int i=1;i<=13;i++){ 44 for(int j=0;j<=13;j++){ 45 if(cnt[i]>=3&&cnt[j]>=2){ 46 cnt[i]-=3;cnt[j]-=2; 47 dfs(sum-5,stp+1); 48 cnt[i]+=3;cnt[j]+=2; 49 } 50 } 51 } 52 //炸弹 53 for(int i=1;i<=13;i++){ 54 if(cnt[i]>=4){ 55 cnt[i]-=4;dfs(sum-4,stp+1);cnt[i]+=4; 56 } 57 } 58 //三带一 59 for(int i=1;i<=13;i++){ 60 for(int j=0;j<=13;j++){ 61 if(cnt[i]>=3&&cnt[j]>=1){ 62 cnt[i]-=3;cnt[j]--; 63 dfs(sum-4,stp+1); 64 cnt[i]+=3;cnt[j]++; 65 } 66 } 67 } 68 //三张牌 69 for(int i=1;i<=13;i++){ 70 if(cnt[i]>=3){ 71 cnt[i]-=3;dfs(sum-3,stp+1);cnt[i]+=3; 72 } 73 } 74 //对子牌,火箭 75 for(int i=0;i<=13;i++){ 76 if(cnt[i]>=2){ 77 cnt[i]-=2;dfs(sum-2,stp+1);cnt[i]+=2; 78 } 79 } 80 //单张牌 81 for(int i=0;i<=13;i++){ 82 if(cnt[i]>=1){ 83 cnt[i]--;dfs(sum-1,stp+1);cnt[i]++; 84 } 85 } 86 } 87 int main(){ 88 cin>>t>>n; 89 while(t--){ 90 memset(a,0,sizeof(a)); 91 memset(b,0,sizeof(b)); 92 ans=INF; 93 for(int i=1;i<=n;i++){ 94 cin>>a[i]>>b[i];cnt[a[i]]++; 95 } 96 dfs(n,0); 97 cout<<ans<<endl; 98 } 99 }
斗地主
猜你喜欢
转载自www.cnblogs.com/lcan/p/9763179.html
今日推荐
周排行