POJ2794 Double Patience[离散概率 状压DP]
Time Limit: 3000MS | Memory Limit: 65536K | |
Total Submissions: 694 | Accepted: 368 | |
Case Time Limit: 1000MS | Special Judge |
Description
After the cards are laid down, the player makes turns. In a turn he can take top cards of the same rank from any two piles and remove them. If there are several possibilities, the player can choose any one. If all the cards are removed from the table, the player wins the game, if some cards are still on the table and there are no valid moves, the player loses.
George enjoys playing this patience. But when there are several possibilities to remove two cards, he doesn't know which one to choose. George doesn't want to think much, so in such case he just chooses a random pair from among the possible variants and removes it. George chooses among all possible pairswith equal probability.
For example, if the top cards are KS, KH, KD, 9H, 8S, 8D, 7C, 7D, and 6H, he removes any particular pair of (KS, KH), (KS, KD), (KH, KD), (8S, 8D), and (7C, 7D) with the equal probability of 1/5.
Once George's friend Andrew came to see him and noticed that he sometimes doesn't act optimally. George argued, that it is not important - the probability of winning any given patience with his strategyis large enough.
Help George to prove his statement - given the cards on the table in the beginning of the game, find out what is the probability of George winning the game if he acts as described.
Input
Each card is described with two characters: one for rank, one for suit. Ranks are denoted as '6' for six, '7' for seven, '8' for eight, '9' for nine, 'T' for ten, 'J' for jack, 'Q' for queen, 'K' for king, and 'A' for ace.
Suits are denoted as 'S' for spades, 'C' for clubs, 'D' for diamonds, and 'H' for hearts. For example, "KS" denotes the king of spades.
Card descriptions are separated from each other by one space.
Output
Sample Input
AS 9S 6C KS
JC QH AC KH
7S QD JD KD
QS TS JS 9H
6D TD AD 8S
QC TH KC 8D
8C 9D TC 7C
9C 7H JH 7D
8H 6S AH 6H
Sample Output
0.589314
Source
//
// main.cpp
// poj2794
//
// Created by Candy on 26/10/2016.
// Copyright ? 2016 Candy. All rights reserved.
// #include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;
const int N=2e6+,M=;//!
double d[N];
char c[][],s[],vis[N];
double dp(int u){//printf("dp %d\n",u);
if(vis[u]) return d[u];
vis[u]=;
int a[],cnt=;
for(int i=,t=u;i<=;i++,t/=) a[i]=t%;//,printf("a %d %d\n",t,i,a[i]);
for(int i=;i<=;i++)
for(int j=i+;j<=;j++)
if(a[i]&&a[j]&&c[i][a[i]]==c[j][a[j]]){
cnt++;
int t=;
for(int k=;k>=;k--){
t*=;
if(k==i||k==j) t+=a[k]-;
else t+=a[k];
}
d[u]+=dp(t);
}
if(cnt)d[u]/=(double)cnt;
return d[u];
}
int main(int argc, const char * argv[]){
for(int i=;i<=;i++)
for(int j=;j<=;j++){
scanf("%s",s+);
c[i][j]=s[];
}
d[]=1.0;
printf("%.6f",dp(M));
return ;
}
POJ2794 Double Patience[离散概率 状压DP]的更多相关文章
- Codeforces Round #363 LRU(概率 状压DP)
状压DP: 先不考虑数量k, dp[i]表示状态为i的概率,状态转移方程为dp[i | (1 << j)] += dp[i],最后考虑k, 状态表示中1的数量为k的表示可行解. #incl ...
- NOIP2016提高A组 A题 礼物—概率状压dp
题目描述 夏川的生日就要到了.作为夏川形式上的男朋友,季堂打算给夏川买一些生 日礼物. 商店里一共有n种礼物.夏川每得到一种礼物,就会获得相应喜悦值Wi(每种礼物的喜悦值不能重复获得). 每次,店员会 ...
- [BZOJ5006][LOJ#2290][THUWC2017]随机二分图(概率+状压DP)
https://loj.ac/problem/2290 题解:https://blog.csdn.net/Vectorxj/article/details/78905660 不是很好理解,对于边(x1 ...
- Luogu4547 THUWC2017 随机二分图 概率、状压DP
传送门 考虑如果只有$0$组边要怎么做.因为$N \leq 15$,考虑状压$DP$.设$f_i$表示当前的匹配情况为$i$时的概率($i$中$2^0$到$2^{N-1}$表示左半边的匹配情况,$2^ ...
- HDU 4336 容斥原理 || 状压DP
状压DP :F(S)=Sum*F(S)+p(x1)*F(S^(1<<x1))+p(x2)*F(S^(1<<x2))...+1; F(S)表示取状态为S的牌的期望次数,Sum表示 ...
- 多校7 HDU5816 Hearthstone 状压DP+全排列
多校7 HDU5816 Hearthstone 状压DP+全排列 题意:boss的PH为p,n张A牌,m张B牌.抽取一张牌,能胜利的概率是多少? 如果抽到的是A牌,当剩余牌的数目不少于2张,再从剩余牌 ...
- BZOJ_1076_[SCOI2008]奖励关_状压DP
BZOJ_1076_[SCOI2008]奖励关_状压DP 题意: 你正在玩你最喜欢的电子游戏,并且刚刚进入一个奖励关.在这个奖励关里,系统将依次随机抛出k次宝物, 每次你都可以选择吃或者不吃(必须在抛 ...
- 【xsy1596】旅行 期望+状压DP
题目大意:有$m$个人要从城市$1$开始,依次游览城市$1$到$n$. 每一天,每一个游客有$p_i$的概率去下一个城市,和$1-p_i$的概率结束游览. 当游客到达城市$j$,他会得到$(1+\fr ...
- Educational Codeforces Round 13 E. Another Sith Tournament 状压dp
E. Another Sith Tournament 题目连接: http://www.codeforces.com/contest/678/problem/E Description The rul ...
随机推荐
- WPF筛选、排序和分组
可以通过CollectionViewSource或者CollectionView对视图进行排序.筛选和分组. 一.通过CollectionViewSource listingDataView是Coll ...
- Java 9将采用新的版本字符串格式
在现有的版本编码格式使用了两年之后,从Java 9开始,Java版本方案将根据业内软件版本编码的最佳实践进行修改.使用或解析Java版本字符串的应用程序开发人员要注意了,因为这种变化 ...
- html节点属性操作
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- 【Java每日一题】20161212
package Dec2016; public class Ques1212 { public static void main(String[] args){ System.out.println( ...
- 排列组和在c语言中的应用
排列组和在c中很常见,但是这个排列组和是通过循环来实现的,和数学中的还是有一点区别的,而且c中的方法也不尽相同,而且我遇到c中的数学问题总会纠结于数学上是怎么实现的但是我自己又不会,所以就没了兴趣,例 ...
- 关于Lind.DDD.Api客户端的使用与知识分享
回到目录 关于Lind.DDD.Api的使用与客户端的调用 作者:张占岭 花名:仓储大叔 框架:Lind.DDD,Lind.DDD.Api 目录 Api里注册全局校验特性 1 Api中设置全局的Cor ...
- Tomcat启动报错整理
1.启动报 Connector attribute SSLCertificateFile must be defined when using SSL with APR conf\server.xml ...
- 最短路径——Floyd-Warshall算法
Floyd-Warshall算法,简称Floyd算法,用于求解任意两点间的最短距离,时间复杂度为O(n^3). 我们平时所见的Floyd算法的一般形式如下: void Floyd() { int i, ...
- js实现web网页版台球游戏
js桌球小游戏在线试玩地址:http://keleyi.com/game/13/ 游戏截图: 完整代码,保存到html文件可以试玩: <!DOCTYPE html PUBLIC "-/ ...
- xp操作系统下配置iis,出现了server application error的解决办法
在网上搜索了很多解决办法,最后发现一个差不多的: Server Application Error The server has encountered an error while loading ...