题目传送门

题意:告诉你C(m,3)个队伍相互之间的胜率,然后要你依次对战n个AI队伍,首先任选一种队伍,然后战胜一个AI后可以选择替换成AI的队伍,也可以不换,问你最后最大的胜率是多少。

分析:dp[i][j][0/1] 表示第i个AI,用j的id去攻打,此j可以是上一个状态交换AI的id而来也可以不是,状态转移方程:

dp[i][j][0] = max (dp[i-1][j][0], dp[i-1][j][1]) * p[j][a[i]];
if (i > 1)
dp[i][a[i-1]][1] = max (dp[i][a[i-1]][1], max (dp[i-1][j][0], dp[i-1][j][1]) * p[a[i-1]][a[i]]);

效率并不是很高。。。

/************************************************
* Author :Running_Time
* Created Time :2015/10/24 星期六 13:32:44
* File Name :J.cpp
************************************************/ #include <cstdio>
#include <algorithm>
#include <iostream>
#include <sstream>
#include <cstring>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <list>
#include <map>
#include <set>
#include <bitset>
#include <cstdlib>
#include <ctime>
using namespace std; #define lson l, mid, rt << 1
#define rson mid + 1, r, rt << 1 | 1
typedef long long ll;
const int N = 1e4 + 10;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
const double EPS = 1e-8;
double dp[N][122][2];
double p[122][122];
int a[N]; int main(void) {
int m, r, n;
while (scanf ("%d", &m) == 1) {
if (m == 3) r = 1;
else if (m == 4) r = 4;
else if (m == 5) r = 10;
else if (m == 6) r = 20;
else if (m == 7) r = 35;
else if (m == 8) r = 56;
else if (m == 9) r = 84;
else if (m == 10) r = 120;
for (int i=1; i<=r; ++i) {
for (int j=1; j<=r; ++j) {
scanf ("%lf", &p[i][j]);
}
}
scanf ("%d", &n);
for (int i=1; i<=n; ++i) {
scanf ("%d", &a[i]); a[i]++;
}
memset (dp, 0, sizeof (dp));
for (int i=1; i<=r; ++i) dp[0][i][0] = dp[0][i][1] = 1;
for (int i=1; i<=n; ++i) {
for (int j=1; j<=r; ++j) {
dp[i][j][0] = max (dp[i-1][j][0], dp[i-1][j][1]) * p[j][a[i]];
if (i > 1)
dp[i][a[i-1]][1] = max (dp[i][a[i-1]][1], max (dp[i-1][j][0], dp[i-1][j][1]) * p[a[i-1]][a[i]]);
}
}
double ans = 0;
for (int i=1; i<=r; ++i) ans = max (ans, max (dp[n][i][0], dp[n][i][1]));
printf ("%.6f\n", ans);
} return 0;
}

  

DP ZOJ 3735 Josephina and RPG的更多相关文章

  1. HDU 4800/zoj 3735 Josephina and RPG 2013 长沙现场赛J题

    第一年参加现场赛,比赛的时候就A了这一道,基本全场都A的签到题竟然A不出来,结果题目重现的时候1A,好受打击 ORZ..... 题目链接:http://acm.hdu.edu.cn/showprobl ...

  2. 2013长沙赛区现场赛 J - Josephina and RPG

    J - Josephina and RPG Time Limit:2000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I6 ...

  3. Josephina and RPG

    Josephina and RPG Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others ...

  4. hdu4800 Josephina and RPG 解题报告

    Josephina and RPG Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others ...

  5. ZOJ 3735 dp

    http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3735 好久没做DP题了,一开始没理解题目里的C(M,3)是干什么,原来就是 ...

  6. Josephina and RPG HDU - 4800

    A role-playing game (RPG and sometimes roleplaying game) is a game in which players assume the roles ...

  7. DP ZOJ 3872 Beauty of Array

    题目传送门 /* DP:dp 表示当前输入的x前的包含x的子序列的和, 求和方法是找到之前出现x的位置(a[x])的区间内的子序列: sum 表示当前输入x前的所有和: a[x] 表示id: 详细解释 ...

  8. 概率dp ZOJ 3640

    Help Me Escape Time Limit:2000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu Submit ...

  9. DP ZOJ 2745 01-K Code

    题目传送门 题意:要求任意连续子序列中0和1的数量差不超过k的方案数 分析:想好状态其实不难.dp[i][j][k]表示考虑前i长度,后缀中最大的 sum(0) - sum(1) = j, sum ( ...

随机推荐

  1. Parencodings(imitate)

    Parencodings Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 20679   Accepted: 12436 De ...

  2. [Effective JavaScript 笔记]第51条:在类数组对象上复用通用的数组方法

    前面有几条都讲过关于Array.prototype的标准方法.这些标准方法被设计成其他对象可复用的方法,即使这些对象并没有继承Array. arguments对象 在22条中提到的函数argument ...

  3. [BZOJ1163][BZOJ1339][Baltic2008]Mafia

    [BZOJ1163][BZOJ1339][Baltic2008]Mafia 试题描述 匪徒准备从一个车站转移毒品到另一个车站,警方准备进行布控. 对于每个车站进行布控都需要一定的代价,现在警方希望使用 ...

  4. [BZOJ2303][Apio2011]方格染色

    [BZOJ2303][Apio2011]方格染色 试题描述 Sam和他的妹妹Sara有一个包含n × m个方格的 表格.她们想要将其的每个方格都染成红色或蓝色. 出于个人喜好,他们想要表格中每个2 × ...

  5. C#关键字base

    例子: public CustomStroke(SharpType type) :base() { this.type = type; } 这里的CustomStroke继承与基类Stroke类,用关 ...

  6. Leetcode 之Validate Binary Search Tree(53)

    判断是否是有效的二叉搜索树,即左子树的值小于根结点,右子树的值大于根结点.可以采用递归的方式来完成,递归时如何 传递有效的参数与根结点进行比较,是此题的难点. bool isValidBST(Tree ...

  7. ssh: connect to host localhost port 22: Connection refused 问题

    错误原因:1.sshd 未安装2.sshd 未启动 3.防火墙 4需重新启动ssh 服务 解决方法:1.确定安装sshd: $ sudo apt-get install openssh-server ...

  8. 【Python】Python AES 对称加密示例

    代码: import sys from Crypto.Cipher import AES from binascii import b2a_hex, a2b_hex AES_SECRET_KEY = ...

  9. tcp/ip程序

    #include<stdio.h> #include<stdlib.h> #include<errno.h> #include<string.h> #i ...

  10. 编译 uImage

    编译 uImage 和测试 u-Boot - 小猪爱拱地 - 博客频道 - CSDN.NET http://blog.csdn.net/caspiansea/article/details/38057 ...