栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

zoj 3423 Jenga

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

zoj 3423 Jenga

#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>#include <cstdlib>using namespace std;const int maxa = 19;const int maxc = 37;const int maxn = 55;double dp[maxa][maxc][maxn][3][2];double b[3][2], d[3][2];inline double P(int i, int j, int n) { return max(0.0, min(1.0, b[i][j] - n * d[i][j]));}double gao(int a, int c, int h, int t, int w) { double &ret = dp[a][c][h][t][w]; if (ret != -1) return ret; if (a == 0 && c == 0) return ret = 0; int a0 = a, h0 = h, w0 = w; w = 1- w; if (t == 0) ++h, ++t; else if (t == 1) ++t; else if (t == 2) ++a, t = 0; ret = 0; if (a0 > 0) { ret = max(ret, P(0, w0, h0) * (1 - gao(a - 1, c, h, t, w))); ret = max(ret, P(1, w0, h0) * (1 - gao(a - 1, c + 1, h, t, w))); } if (c > 0) { ret = max(ret, P(2, w0, h0) * (1 - gao(a, c - 1, h, t, w))); } return ret;}void solved(int nT) { int n; scanf("%d", &n); for (int i = 0; i < 2; ++i) { for (int j = 0; j < 3; ++j) { scanf("%lf %lf", &b[j][i], &d[j][i]); } } fill(dp[0][0][0][0], dp[n+1][0][0][0], -1); printf("%.4lfn", gao(n - 1, 0, n, 0, 0));}int main() { int T = 1; scanf("%d", &T); for (int nT = 1; nT <= T; ++nT) { solved(nT); } return 0;}
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/371853.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号