LightOJ 1364 Expected Cards (概率DP)
来源:互联网 发布:淘宝图片空间 编辑:程序博客网 时间:2024/05/21 10:15
解析:
设dp[c][d][h][s][i][j]为有c,d,h,s个对应的牌,i、j记录大小王的状态。
记忆化搜索一下就ok
[code]:
#include<cstdio>#include<cstring>#include<algorithm>using namespace std;int C,D,H,S,cnt[5];double dp[15][15][15][15][5][5];void init(){ int c,d,h,s,i,j; for(c = 0;c < 14;c++) for(d = 0;d < 14;d++) for(h = 0;h < 14;h++) for(s = 0;s < 14;s++) for(i = 0;i < 5;i++) for(j = 0;j < 5;j++) dp[c][d][h][s][i][j] = -1;}double dfs(int c,int d,int h,int s,int i,int j){ if(c > 13||d > 13||h > 13||s > 13) return 0;//printf("status: %d %d %d %d %d %d\n",c,d,h,s,i,j); cnt[1] = c; cnt[2] = d; cnt[3] = h; cnt[4] = s; if(i) cnt[i]++; if(j) cnt[j]++; if(cnt[1]>=C&&cnt[2]>=D&&cnt[3]>=H&&cnt[4]>=S) return dp[c][d][h][s][i][j] = 0; if(dp[c][d][h][s][i][j] > -0.5) return dp[c][d][h][s][i][j]; int k,num = cnt[1]+cnt[2]+cnt[3]+cnt[4]; double ans = 0,tmp; num = 54 - num; if(num == 0) return 0; if(!i){ tmp = 100; for(k = 1;k <= 4;k++){ tmp = min(tmp,dfs(c,d,h,s,k,j)); } ans += tmp; } if(!j){ tmp = 100; for(k = 1;k <= 4;k++){ tmp = min(tmp,dfs(c,d,h,s,i,k)); } ans += tmp; } ans += (13-c)*dfs(c+1,d,h,s,i,j) + (13-d)*dfs(c,d+1,h,s,i,j) + (13-h)*dfs(c,d,h+1,s,i,j) + (13-s)*dfs(c,d,h,s+1,i,j); ans = ans/num+1; return dp[c][d][h][s][i][j] = ans;}int main(){ int i,j,cas; scanf("%d",&cas); for(int T=1;T<=cas;T++){ scanf("%d%d%d%d",&C,&D,&H,&S); init(); printf("Case %d: ",T); int x = (C > 13? C - 13 : 0) + (D > 13? D - 13 : 0) + (H > 13? H - 13 : 0) + (S > 13? S - 13 : 0); if(x > 2) puts("-1"); else{ printf("%.10f\n",dfs(0,0,0,0,0,0)); } } return 0;}
0 0
- LightOJ 1364 Expected Cards (概率DP)
- LightOJ-1364 Expected Cards(期望dp)
- [LightOJ 1364] Expected Cards (高维期望DP)
- LightOJ1364---Expected Cards(概率dp+三进制状压)
- Expected Cards LightOJ
- LightOJ 1364 Expected Cards(724训练题目)
- BNU Cards 概率dp
- Lightoj 1038 概率DP
- Lightoj 1030 概率DP
- Lightoj 1038 概率DP
- lightoj 概率dp小结
- lightoj 1265 概率dp
- lightoj 1030 概率dp
- Lightoj 1030 概率dp
- Lightoj 1248 概率dp
- Lightoj 1104 概率dp
- lightoj 1038 概率dp
- Lightoj 1265(概率dp)
- 古典密码之维吉尼亚密码破解思路
- 重新学javaweb---路径专题
- 监听器图库
- 安卓开发之java基础篇笔记【1】
- 《极简笔记》源码分析(二)
- LightOJ 1364 Expected Cards (概率DP)
- &&和||的优先级
- hibernate懒加载(lazy加载)
- 介绍NSURLSESSION网络请求套件
- HDU 5671:Matrix【技巧】
- mysql启动和关闭外键约束的方法
- 剑指offer之面试题18:树的子结构
- POJ 1094 Sorting It All Out
- 一个弱鸡_android重走之路