poj 2794 Double Patience(状态dp)
来源:互联网 发布:手机身份证读取软件 编辑:程序博客网 时间:2024/06/12 01:30
题意:
一共有9堆牌,每堆牌四张。每次可以取堆顶点数相同的两张牌,如果有多种方案则选取是随机的。
如果最后将所有牌取完,则视为游戏胜利,求胜利的概率。
分析:
用一个九元组表示状态,分别代表每堆牌剩余的牌数。根据全概率公式,d[i]为后继状态成功概率的平均值。
#include<bits/stdc++.h>using namespace std;#define LL long longmap<vector<int>, float> dp;const int MAXN = 100008;const int MOD = 1e9+7;char s[12][8][6];float dfsdp(vector<int> cnt, int tot) { if (!tot) return 1; if (dp.count(cnt)) return dp[cnt];//count 访问次数 int ans = 0; float res = 0; for(int i = 1; i <= 9; i++) if (cnt[i] > 0) { for(int j = i+1; j <= 9; j++) if (cnt[j] > 0) { if (s[i][cnt[i]][0] == s[j][cnt[j]][0]) { cnt[i]--;cnt[j]--; ans++; res += dfsdp(cnt, tot-1); cnt[i]++;cnt[j]++; } } } if (!ans) return dp[cnt] = 0; return dp[cnt] = res/ans;}bool read_input() { for(int i = 1; i <= 9; i++) { for(int j = 1; j <= 4; j++) { if (scanf("%s", s[i][j]) != 1) return false; } } return true;}int main() { freopen("double.in", "r", stdin); freopen("double.out", "w", stdout); read_input(); vector<int> cnt(10, 4); //前十个数初始为4; dp.clear(); printf("%.6f\n", dfsdp(cnt, 18)); return 0;}
阅读全文
0 0
- poj 2794 Double Patience(状态dp)
- Double Patience - POJ 2794 状压dp
- 1637 - Double Patience (概率DP)
- 1637 - Double Patience(状态转移+求成功概率)
- UVA 1637 Double Patience 概率DP
- UVA 1637 Double Patience(DP+概率)
- UVA 1637 - Double Patience
- [UVA1637]Double Patience && 概率
- UVA 1637 Double Patience
- UVa 1637 Double Patience
- uva 1637 - Double Patience
- Neerc2005 POJ2794 Double Patience
- uva1637 Double Patience
- UVa 1637 Double Patience
- Double Patience UVA
- UVa1637 - Double Patience(离散概率)
- UVa 1637 Double Patience (搜索)
- poj 3254(状态压缩dp专题)
- 前端构建工具gulp
- 激光SLAM导航系列(五)局部路径规划
- 方法重载与方法重写
- 年年最最难就业季
- Linux shell脚本功略第2版笔记--第四章
- poj 2794 Double Patience(状态dp)
- C语言数据类型
- Android Fragment 与 Fragment管理器
- Mybatis 实现物理分页的简单实现
- 关于MySQL建表对DML的影响【转】
- 2017 计蒜之道 初赛 第六场 微软大楼设计方案(中等)【思维+RMQ】
- POJ 1776 Task Sequences 笔记
- 图的学习-huffman code
- 这就是线程