码迷,mamicode.com
首页 > 其他好文 > 详细

[hiho1159] Poker

时间:2017-09-25 22:06:14      阅读:170      评论:0      收藏:0      [点我收藏+]

标签:name   log   space   mem   for   cst   pre   sign   math   

 1 /*
 2   Poker
 3   组合dp
 4 */
 5 #include<iostream>
 6 #include<cstdio>
 7 #include<cstdlib>
 8 #include<cstring>
 9 #include<algorithm>
10 #include<cmath>
11 #define ull unsigned long long 
12 using namespace std;
13 
14 int num[310],cnt[15];
15 ull c[55][55],dp[15][55],fac[10];
16 char alph[15]={"0A23456789TJQK"};
17 
18 int gi() {
19   int x=0,o=1; char ch=getchar();
20   while(ch!=- && (ch<0 || ch>9)) ch=getchar();
21   if(ch==-) o=-1,ch=getchar();
22   while(ch>=0 && ch<=9) x=x*10+ch-0,ch=getchar();
23   return o*x;
24 }
25 
26 void pre() {
27   c[0][0]=1;
28   for(int i=1; i<=52; i++) {
29     c[i][0]=c[i][i]=1;
30     for(int j=1; j<i; j++) {
31       c[i][j]=c[i-1][j-1]+c[i-1][j];
32     }
33   }
34   for(int i=1; i<=13; i++) num[alph[i]]=i;
35   fac[0]=1;
36   for(int i=1; i<=4; i++) fac[i]=fac[i-1]*i;
37 }
38 
39 int main() {
40   pre();
41   int T=gi(),tot,n,t=0;
42   while(T--) {
43     n=gi(),tot=0;
44     memset(cnt,0,sizeof(cnt));
45     for(int i=1; i<=n; i++) {
46       char s[3];
47       scanf("%s", s);
48       cnt[num[s[0]]]++;
49     }
50     memset(dp,0,sizeof(dp));
51     dp[0][0]=1;
52     for(int i=1; i<=13; i++) {
53       if(cnt[i]==0) {
54     for(int j=0; j<=max(0,tot-1); j++)
55       dp[i][j]=dp[i-1][j];
56     continue;
57       }
58       for(int j=0; j<=max(0,tot-1); j++) 
59     for(int k=1; k<=cnt[i]; k++) 
60       for(int l=0; l<=k; l++) 
61         if(j+cnt[i]-k-l>=0)
62           dp[i][j+cnt[i]-k-l]+=dp[i-1][j]*c[cnt[i]-1][k-1]*c[j][l]*c[tot+1-j][k-l];
63       tot+=cnt[i];
64     }
65     ull ans=dp[13][0];
66     for(int i=1; i<=13; i++) {
67       ans=ans*fac[cnt[i]];
68     }
69     printf("Case #%d: %llu\n", ++t,ans);
70   }
71 }

 

[hiho1159] Poker

标签:name   log   space   mem   for   cst   pre   sign   math   

原文地址:http://www.cnblogs.com/HLXZZ/p/7593768.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!