hdu 4800 Josephina and RPG dp
来源:互联网 发布:软件著作权代码格式 编辑:程序博客网 时间:2024/05/17 06:20
Problem Description
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?
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
40.50 0.50 0.20 0.300.50 0.50 0.90 0.400.80 0.10 0.50 0.600.70 0.60 0.40 0.5030 1 2
Sample Output
0.378000
题意:
告诉你有m个人物,三个人可以组一个队,那么有C(m,3)种组队方法,给一个矩阵列出每个队伍之间的胜率,再告诉你有n支ai队伍以及他们的队伍编号,现在你一开始可以任选一支队伍,然后按顺序和每支ai进行比赛,你赢了ai可以选择要不要与它换队伍来进行下一场的比赛,求最大的胜率。
思路:
简单dp,d[i][j]代表第i场比赛后你的队伍编号为j时的最大胜率。
d[i][j]=max(d[i][j],mp[j][a[i]]*d[i-1][j]);
d[i][a[i]]=max(d[i][a[i]],mp[j][a[i]]*d[i-1][j]);
其中mp[i][j]为i对j的胜率,a[i]为第i支队伍的编号。
#include <iostream>#include<cstring>#include<cstdio>#include<algorithm>#include<cmath>#define ll long long using namespace std;int n, m,a[11000];double mp[150][150],d[11000][150];int main(int argc, const char * argv[]) { while(~scanf("%d",&m)) { int t=m*(m-1)*(m-2)/6; m=t; for(int i=0;i<m;i++) for(int j=0;j<m;j++) scanf("%lf",&mp[i][j]); scanf("%d",&n); for(int i=0;i<n;i++) scanf("%d",&a[i]); memset(d,0,sizeof(d)); for(int i=0;i<m;i++) { d[0][i]=max(mp[i][a[0]],d[0][i]); d[0][a[0]]=max(mp[i][a[0]],d[0][a[0]]); } for(int i=1;i<n;i++) { for(int j=0;j<m;j++) { d[i][j]=max(d[i][j],mp[j][a[i]]*d[i-1][j]); d[i][a[i]]=max(d[i][a[i]],mp[j][a[i]]*d[i-1][j]); } } double ans=0; for(int i=0;i<m;i++) ans=max(ans,d[n-1][i]); printf("%.12f\n",ans); }}
阅读全文
0 0
- hdu 4800 Josephina and RPG dp
- HDU - 4800 Josephina and RPG(dp)
- HDU 4800 Josephina and RPG DP
- hdu 4800 Josephina and RPG(dp)
- hdu 4800 Josephina and RPG【dp】
- HDU 4800 Josephina and RPG【概率DP】
- HDU 4800 Josephina and RPG【概率dp】
- hdu 4800 Josephina and RPG dp
- hdu 4800 Josephina and RPG
- HDU 4800 & ZJU 3735 Josephina and RPG(dp)
- hdu 4800 Josephina and RPG dp(概率类,较简单)
- hdu 4800 Josephina and RPG (概率dp)
- HDU-4800 & ZJU-3735 Josephina and RPG
- hdu 4800 Josephina and RPG (动态规划)
- HDU 4800 Josephina and RPG(动态规划)
- ZOJ 3735 Josephina and RPG DP
- ZOJ 3735 Josephina and RPG (dp)
- ZOJ3735 Josephina and RPG(简单DP)
- git 常用指令
- Leetcode-1. Two Sum
- Spring回顾(二)注解实现IoC和DI
- POJ2352——BIT基础
- linux中常用指令tcpdump
- hdu 4800 Josephina and RPG dp
- poj 1195
- JAVA序列化和反序列化
- 统计 MySQL 数据库中每个表数据与索引占用的空间大小
- java环境变量设置方法总结
- 零基础搭建Hadoop大数据处理-环境
- idea build.sbt indexRDD jar包加载不成功
- 4081:树的转换
- JavaWeb学习总结—文件上传和下载