A role-playing game (RPG and sometimes roleplaying game) is a game in which players assume the roles of characters in a fictional setting. Players take responsibility for acting out these roles within a narrative, either through literal acting or through a process of structured decision-making or character development. 
Recently, Josephina is busy playing a RPG named TX3. In this game, M characters are available to by selected by players. In the whole game, Josephina is most interested in the "Challenge Game" part. 
The Challenge Game is a team play game. A challenger team is made up of three players, and the three characters used by players in the team are required to be different. At the beginning of the Challenge Game, the players can choose any characters combination as the start team. Then, they will fight with N AI teams one after another. There is a special rule in the Challenge Game: once the challenger team beat an AI team, they have a chance to change the current characters combination with the AI team. Anyway, the challenger team can insist on using the current team and ignore the exchange opportunity. Note that the players can only change the characters combination to the latest defeated AI team. The challenger team gets victory only if they beat all the AI teams. 
Josephina is good at statistics, and she writes a table to record the winning rate between all different character combinations. She wants to know the maximum winning probability if she always chooses best strategy in the game. Can you help her? 

Input

There are multiple test cases. The first line of each test case is an integer M (3 ≤ M ≤ 10), which indicates the number of characters. The following is a matrix T whose size is R × R. R equals to C(M, 3). T(i, j) indicates the winning rate of team i when it is faced with team j. We guarantee that T(i, j) + T(j, i) = 1.0. All winning rates will retain two decimal places. An integer N (1 ≤ N ≤ 10000) is given next, which indicates the number of AI teams. The following line contains N integers which are the IDs (0-based) of the AI teams. The IDs can be duplicated.

Output

For each test case, please output the maximum winning probability if Josephina uses the best strategy in the game. For each answer, an absolute error not more than 1e-6 is acceptable.

Sample Input

4
0.50 0.50 0.20 0.30
0.50 0.50 0.90 0.40
0.80 0.10 0.50 0.60
0.70 0.60 0.40 0.50
3
0 1 2

Sample Output

0.378000

题目大意就是: RPG游戏中有很多不同的角色,选择其中三个组成一支队伍,现已知每支队伍打败其他队伍的概率,然后给你一个需要打败的队伍的顺序,求打败所有队伍的最大的概率是多少。

其实就是一道概率DP的题目,换或者不换。

对需要打败的队伍进行枚举,考虑换了队伍和不换队伍两者概率大小,取最大的那种。

// Asimple
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <cstring>
#include <stack>
#include <set>
#include <map>
#include <cmath>
#define INF 0x3f3f3f3f
#define debug(a) cout<<#a<<" = "<<a<<endl
#define test() cout<<"============"<<endl
#define CLS(a,v) memset(a, v, sizeof(a))
#define pas system("pause")
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
int dx[] = {-,,,,-,-,,}, dy[]={,,-,,-,,,-};
const int maxn = +;
const ll mod = ;
ll n, m, T, len, cnt, num, ans, Max, k;
//vector<int> a[maxn];
double dp[maxn];
double Map[][];
int team[maxn]; void input(){
while( scanf("%lld", &n)!=EOF) {
n = n*(n-)*(n-)/;
double res = 1.0;
for(int i=; i<n; i++) {
for(int j=; j<n; j++) {
scanf("%lf", &Map[i][j]);
}
dp[i] = 1.0;
}
scanf("%lld", &m);
for(int i=; i<m; i++) scanf("%d", &team[i]);
for(int i=; i<m; i++) {
double te = 0.0;
for(int j=; j<n; j++) {
te = max(Map[j][team[i]]*dp[j], te);
dp[j] = dp[j] * Map[j][team[i]];
}
dp[team[i]] = te;
}
printf("%.6lf\n", dp[team[m-]]);
}
// pas;
} int main() {
input();
return ;
}

Josephina and RPG HDU - 4800的更多相关文章

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

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

  2. Josephina and RPG

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

  3. hdu4800 Josephina and RPG 解题报告

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

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

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

  5. hdu 4800 Josephina and RPG

    简单dp #include<cstdio> #define maxn 10005 #include<cstring> #include<algorithm> usi ...

  6. DP ZOJ 3735 Josephina and RPG

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

  7. The 2013 ACM-ICPC Asia Changsha Regional Contest - J

    Josephina and RPG Time Limit: 2 Seconds      Memory Limit: 65536 KB      Special Judge A role-playin ...

  8. [HDU 2068] RPG的错排 (错排问题)

    RPG的错排 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2068 题目大意: 有N个人对应N个名字,然后你去把每一个名字对应到每个人,只要求答对一半 ...

  9. HDU 2045 不容易系列之(3)—— LELE的RPG难题(递归/动态规划)

    不容易系列之(3)—— LELE的RPG难题 Problem Description 人称“AC女之杀手”的超级偶像LELE最近忽然玩起了深沉,这可急坏了众多“Cole”(LELE的粉丝,即" ...

随机推荐

  1. python 读取文本文档中的数据

    import os dir = input('Please input the file dir:')#提示输入文件路径 while not os.path.exists(dir):#判断文件是否存在 ...

  2. stm32通用定时器详解

    在stm32的开发中我们经常会用到定时器,因此在学习stm32的过程中定时器是必须要学的,而定时主要又分为三大类分别为: 高级控制定时器(TIM1与TIM8) 通用定时器(TIM2~TIM5) 基本定 ...

  3. 【UNIX环境高级编程】文件I/O

    [UNIX环境高级编程]文件I/O大多数文件I/O只需要5个函数: open.read.write.lseek以及close 不带缓冲的I/O: 每个read和write都调用内核中的一个系统调用 1 ...

  4. Alibaba, I'm interested in you.

    Working for Alibaba is an aspiration for some. For other it’s the possibility of lucrative stock opt ...

  5. linux cp 拷贝文件或目录

    cp 拷贝文件或目录 默认不能拷贝目录 常用来备份: [root@MongoDB ~]# cp a.txt /tmp/ [root@MongoDB ~]# cp /root/a.txt /tmp/ c ...

  6. 异常处理之IIS配置加载出错

    问题详情:  一台部署在海外服务器,在管理IIS过程中,出现问题 There was an error when trying to connect. Do you want > to rety ...

  7. macOS 版微信小助手,支持微信多开、防撤回、远程控制mac、自动回复等等

    微信小助手 GitHub大牛提供的微信小助手是一款插件,该插件具备多开.防撤回.免手机认证登录.自动回复.远程控制自己的 macOS.群发等众多功能 GitHub网址:https://github.c ...

  8. hystrix参数使用方法

    hystrix+feign+ribbon,但是可能很多人都知道hystrix还有线程隔离,信号量隔离,等等各种参数配置,在这几就记录下hystrix的参数, 一.hystrix参数使用方法 通过注解@ ...

  9. Git常用功能记录

    1. git查看某个文件的修改历史 git log --pretty 然后使用下面的命令可列出文件的所有改动历史,注意,这里着眼于具体的一个文件,而不是git库,如果是库,那改动可多了去了- git ...

  10. spring boot集成aop实现日志记录

    1.pom依赖 <dependency> <groupId>org.springframework.boot</groupId> <artifactId> ...