HDU-5816-Hearthstone-DP+数学推导
来源:互联网 发布:消音软件哪个好 编辑:程序博客网 时间:2024/06/05 07:10
题意:有两种牌,A使用后可以再抽两张牌,B使用后可以减少对方x点生命值,对方开始p点生命值
思路:
因为每次抽牌,结束时要不就是xa+1=xb或者是全部取完(n>=m)
所以先DP初始化一下dp[i][j]表示抽出i张A卡和j张B卡的合法种数
然后dfs暴力枚举一下f[i]表示i张B大于p的种数
最后对于每一种i-1张A和i张B都有
ans+=C(n,i-1)*fac[i-1]*dp[i-1][i]*f[i]*fac[i]*fac[n+m-2*i+1];
///C(n,i-1)*fac[i-1] A的排列数 选i-1张A全排
///f[i]*fac[i] B的可行方案,乘全排
///dp[i-1][i] A和B的组合排列数
///fac[n+m-2*i+1] 剩余那些数的牌的全排列
最后如果n>=m加上全部取完的种数
ans+=f[m]*dp[n][m]*fac[n]*fac[m];
最后约分一下就好了
#include<bits/stdc++.h>#define maxn 22using namespace std;long long fac[maxn];///阶乘long long dp[maxn][maxn];///i张Aj张B合法的抽牌顺序long long f[maxn];///i张B大于p的方案数int p,n,m;int a[maxn];void dfs (int pos, long long sum, int cnt) { ///求f[i] i张B和大于p的个数 if (pos == m+1) { if (sum >= p) f[cnt]++; return ; } dfs (pos+1, sum+a[pos], cnt+1); dfs (pos+1, sum, cnt);}void init(void) { ///初始阶乘 fac[0]=1; fac[1]=1; for(int i=2;i<=21;i++) fac[i]=fac[i-1]*i;}long long C(int x,int y) { ///组合数 return fac[x]/fac[x-y]/fac[y];}int main(){ init(); int t; scanf("%d",&t); while(t--) { memset(dp,0,sizeof dp); memset(f,0,sizeof f); scanf("%d%d%d",&p,&n,&m); for(int i=1;i<=m;i++) scanf("%d",&a[i]); if(p==0) { printf("1/1\n"); continue; } dfs(1,0,0); dp[0][0]=1; for(int i=0;i<=n;i++) ///初始化i张A,j张B可行的排列方案 for(int j=0;j<=m;j++) { if(i<n&&i>=j) { dp[i+1][j]+=dp[i][j]; } if(j<m&&i>=j) { dp[i][j+1]+=dp[i][j]; } } long long ans=0; for(int i=1;i<=m;i++) { if(i-1<=n) ///A不能被取玩 ans+=C(n,i-1)*fac[i-1]*dp[i-1][i]*f[i]*fac[i]*fac[n+m-2*i+1]; ///C(n,i-1)*fac[i-1] A的排列数 选i-1张A全排 ///f[i]*fac[i] B的可行方案,乘全排 ///dp[i-1][i] A和B的组合排列数 ///fac[n+m-2*i+1] 剩余那些数的牌的全排列 } if(n>=m) { ans+=f[m]*dp[n][m]*fac[n]*fac[m]; ///先取出A,然后全把B给取完了,条件是n>=m } long long tot=fac[n+m];///总方案数 long long tt=__gcd(ans,tot); if(tt==0) { printf("0/1\n"); } else { printf("%lld/%lld\n",ans/tt,tot/tt); } } return 0;}
0 0
- HDU-5816-Hearthstone-DP+数学推导
- hdu 5816 Hearthstone (状压dp)
- hdu 5816 Hearthstone 状态dp
- [HDU 5816] Hearthstone (概率DP+状压)
- Hdu-5816 Hearthstone(状态压缩DP)
- HDU 5816 Hearthstone (状压dp)
- HDU 5816 Hearthstone(概率DP+状压)
- HDU 5816 Hearthstone (状压dp)
- HDU 5816 Hearthstone (状压dp+概率)
- HDU 5816 Hearthstone(状压DP)
- HDU 5816 Hearthstone (Probability dp, Conbinations)
- hdu 5816 Hearthstone 状压DP+记忆化搜索
- HDU 5816 Hearthstone(状态压缩DP+概率)
- HDU 5816 Hearthstone
- HDU 5816 Hearthstone
- HDU 5816 Hearthstone
- hdu5117(数学推导+dp)
- HDU 4919 (数学推导)
- CodeForces 589J -- J. Cleaner Robot (BFS)
- 当你对着一个应用程序双击后发生了什么
- 如何理解奇偶校验只能发现数据代码中奇数位出错的情况
- Win10系统精简
- CoordinatorLayout与滚动的处理
- HDU-5816-Hearthstone-DP+数学推导
- HDU 4422 采蘑菇的小女孩
- group by、having以及order by
- UVA 658 It's not a Bug, it's a Feature! (特殊图最短路)
- [Servlet]Servlet生命周期
- 数据收发的软中断以及数据从网卡发送
- 网页ad广告图下拉定点滑动
- CodeForces 650B(二分)
- Getting Started with the G1 Garbage Collector (待翻译)