[hiho1159] Poker

 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 }
时间: 2025-01-14 15:27:47

[hiho1159] Poker的相关文章

作业:JavaScript(数组篇-poker)给我的徒弟出个题。。。记得早点写完,然后大家3人可以早点打牌了

吐槽一下:“今天实际上我左思右想,写个什么东西好呢!手上的笔转了半天....最后还是给自己留点余地!看着他们什么酒店管理系统,呼叫中心系统之类的....简直是把自己固定死了!感觉一撸到底的感觉!!!我们是程序员所以我觉得要思想灵活点HOHO...” 今天只是想写一篇关于JavaScript数组的一篇文章 以前我认为我已经完全把数组掌握了!但是去年面试的时候被问呆了!!瞬间感觉自己萌萌哒!!所以把书看完了不算会!所以这次为了让我的徒弟能够不再犯我当年的错误...哼哼!我决定让她来一次实战!!!不能

如何生成一副Poker

import java.util.LinkedList;import java.util.Random;//扑克类class Poker{    String color;//花色    String num;//点数    public Poker (String color,String num) {        this.color=color;        this.num =num;    }    public String toString() {        return

ZOJ 1111 Poker Hands

题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=1111 A poker hand consists of 5 cards dealt from the deck. Poker hands are ranked by the following partial order from lowest to highest High Card. Hands which do not fit any higher cat

UVa 131 - The Psychic Poker Player

题目:手里有五张牌,桌上有一堆牌(五张),你可以弃掉手中的k张牌,然后从牌堆中取最上面的k个. 比较规则如下:(按优先级排序) 1.straight-flush:同花顺,牌面为T(10) - A,这里不论花色是否相同: 2.four-of-a-kind:四条,牌面有4个相同的值: 3.full-house:船牌,牌面有3个相同值,剩下2个也相同值: 4.flush:同花,五张牌的花色相同,不是同花顺: 5.straight:顺子,五张牌的值连续,A可以作为1也可以作为14: 6.three-of

Codeforce 573A. Bear and Poker

Limak is an old brown bear. He often plays poker with his friends. Today they went to a casino. There are nplayers (including Limak himself) and right now all of them have bids on the table. i-th of them has bid with size ai dollars. Each player can

002 -- Circle LinkList 3 -- Puzzels_Magic Poker and Latin

000--Magic Poker Put the poker with specific sequence, so that they can show as below: count 1, open the first card as A, count 2, the first one place to bottom and open the second one as 2; for 3, the first 2 cards put to the bottom, and open the th

西交校赛 F. GZP and Poker

F. GZP and Poker GZP often plays games with his friends.Today they went to a board game.There are n players(including GZP) and all of them have some virtual money on the table. ith of them has ai yuan. Each player can double his virtual wealth any nu

uva 131 The Psychic Poker Player (暴力枚举)

uva 131 The Psychic Poker Player  The Psychic Poker Player  In 5-card draw poker, a player is dealt a hand of five cards (which may be looked at). The player may then discard between zero and five of his or her cards and have them replaced by the sam

Poker End Games

题目链接 题意: 初始为一个数对(a,b),每回合从a到b或者从b到a转移min(a,b),最后如果b为零,获胜 求能进行的回合数的期望和获胜的概率 For both these valueserrors less than 10e-5will be ignored 分析: 这个题目关键在于误差为1e-5比较大,所以其实不用高斯消元,直接DFS忽略环形.因为大约递归20层左右就可以结束了(此时近似为0),所以暴力DFS即可 可以不用高斯消元的原因: 1.误差要求不是很高 2.每个状态恰好转移到两