//UVA1637DoublePatience
#include<cstdio>
#include<cstring>
#include<vector>
#include<map>
using namespace std;
char input[9][4][3];
map<vector<int>, double> d;
double dp(vector<int>& cnt, int c) {//c记录剩余牌的数量
//多阶段决策
if(c == 0) return 1;//可能性为1
if(d.count(cnt)) return d[cnt];//记忆化搜索
int tot = 0;
double sum = 0;
for(int i = 0; i < 9; i++) {
if(cnt[i] > 0)
for(int j = i + 1; j < 9; j++)
if(cnt[j] > 0) {
if(input[i][cnt[i] - 1][0] == input[j][cnt[j] - 1][0]) {
tot++;//可行方案数+1
cnt[i]--; cnt[j]--;
sum += dp(cnt, c - 2);
cnt[i]++; cnt[j]++;
}
}
}
if(tot < 1) return d[cnt] = 0;//可能性为0
else return d[cnt] = sum / tot;
}
bool In() {
for(int i = 0; i < 9; i++) {
for(int j = 0; j < 4; j++) {
if(scanf("%s", input[i][j]) != 1) return false;
}//值得学习的输入技巧
}
return true;
}
int main() {
while(In()) {
d.clear();
vector<int> cnt(9, 4);//记录每堆剩余的牌的数量
//初始化为9个值均为4的元素,比用数组便捷
printf("%.6lf\n", dp(cnt, 36));
}
return 0;
}
/*
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
*/
UVA1637DoublePatience
最新推荐文章于 2019-05-03 12:23:09 发布