hdu 4800 Josephina and RPG(dp)
2015-11-14 21:10
363 查看
题目链接:hdu 4800 Josephina and RPG
代码
#include <cstdio> #include <cstring> #include <algorithm> using namespace std; const int maxn = 10005; const int maxm = 125; int M; double G[maxm][maxm], dp[maxn][maxm]; double solve () { int n, x; scanf("%d", &n); for (int i = 0; i < M; i++) dp[0][i] = 1; for (int i = 0; i < n; i++) { scanf("%d", &x); dp[i+1][x] = 0; for (int j = 0; j < M; j++) { double p = G[j][x]; if (j != x) dp[i+1][j] = dp[i][j] * p; dp[i+1][x] = max(dp[i][j] * p, dp[i+1][x]); } } double ans = 0; for (int i = 0; i < M; i++) ans = max(ans, dp [i]); return ans; } int main () { while (scanf("%d", &M) == 1) { M = M * (M-1) * (M-2) / 6; for (int i = 0; i < M; i++) for (int j = 0; j < M; j++) scanf("%lf", &G[i][j]); printf("%.6lf\n", solve()); } return 0; }
相关文章推荐
- android中Serializable 和 Parcelable 的区别
- Struts2_include
- hibernate执行存储过程
- B. Cola (暴力+优化)
- ip地址与整数之间的转换
- 【TCP/IP协议】四层协议系统
- Android创建前台运行的Service(不会被系统杀死)
- hdu 4799 LIKE vs CANDLE(树形dp)
- 数组名做函数参数,将a[10]中元素反序
- IDR帧
- 工艺问题
- 【转】基础知识系列4--队列
- Linux之格式化与挂载
- Android之混淆代码总结
- pathmatcher 接口和其子接口
- HDU1143(3*N的地板铺1*2的砖)
- OPENCV中BFMatcher(BruteForceMatcher)和FlannBasedMatcher区别
- SDUT OJ数据结构实验之二叉树三:统计叶子数
- 如何免 sudo 使用 docker
- 苹果开发——设置iTunes Connect中的Contracts, Tax, and Banking