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. CSS3属性上调

    一.为什么使用CSS 1.有效的传递页面信息 2.使用CSS美化过的页面文本,使页面漂亮.美观,吸引用户 3.可以很好的突出页面的主题内容,使用户第一眼可以看到页面主要内容 4.具有良好的用户体验 二 ...

  2. 转:浅谈SimpleDateFormat的线程安全问题

    转自:https://blog.csdn.net/weixin_38810239/article/details/79941964 在实际项目中,我们经常需要将日期在String和Date之间做转化, ...

  3. C#获取本周五日期字符串

    using System; using System.Collections.Generic; using System.Globalization; using System.Linq; using ...

  4. 安装配置Greenplum

    一.规划 1.服务器: 192.168.0.191   gpdb01        # master 192.168.0.192   gpdb02        # primary segment . ...

  5. 新手上路、安装JDK教程

    按照以下的图片步骤,登录http://www.oracle.com 下载 JDK (J2SE)  JDK 1.0, 1.1, 1.2, 1.3, 1.4    1.5.(JDK5.0) → 支持注解. ...

  6. 2018-2019-2 《网络对抗技术》Exp0 Kali安装 Week1 20165317

    第一周作业 Kali的安装 Kali的下载 从kali官网下载kali-linux 64-bit 版本. Kali的安装 由于在娄老师的课上使用virtualbox, 所以我习惯性使用virtual ...

  7. 基于Dockerfile创建docker镜像

    0.先创建一个文件夹img mkdir img 1.Linux上新建3个文件 2.文件内容分别写入 (1)Dockerfile中 # 基于的基础镜像centos FROM centos # 维护该镜像 ...

  8. 使用springmvc进行文件的上传和下载

    文件的上传 SpringMVC支持文件上传组件,commons-fileupload,commons-fileupload依赖commons-io组件 配置步骤说明 第一步:导入包 commons-f ...

  9. 【转】mysql保存图片技术决定:保存二进制文件还是只保存图片相对路径,图片放在硬盘上面?

    最近遇到上面这个问题,一开始我就果断否决了数据库保存图片的策略,主要是太蠢!事实上我的决定是正确的,我仅仅理解为mysql读写性能提高的境界,具体为什么可以提高?很模糊,知道我看到了这里: 大佬做的实 ...

  10. DAX/PowerBI系列 - 关于时间系列 - 时间相关数值比较 - 用非自带函数

    DAX/PowerBI系列 - 关于时间系列 - 时间相关数值比较 - 用非自带函数 文末有彩蛋,解决蛋疼问题 难度: ★★☆☆☆(2星) 适用范围: ★★★☆☆(3星) 概况: 基于时间的汇总可能是 ...