zoj 3735 Josephina and RPG (2013 亚洲区域赛 长沙站 J)


http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3735 


Josephina and RPG

Time Limit: 2 Seconds       Memory Limit: 65536 KB       Special Judge

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 get 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?



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

思路:很简单的DP,设dp[i][j]表示打第i个敌人时用第j种队伍的最大胜率,那么状态转移有两种,设p[x][y]表示第x种队伍对第y种队伍的胜率,设第i个AI是队伍k。那么我们有:

dp[i][j]=p[j][k]*max(dp[i+1][j],dp[i+1][k]),第一种表示不换,第二种表示换。最后求dp[1][j]的最大值即可。

代码如下:


#include <iostream>
#include <string.h>
#include <stdio.h>
#include <algorithm>
#define maxn 10010
using namespace std;
int num[11]={0,0,0,1,4,10,20,35,56,84,120};
double dp[maxn][125];
double map[125][125];
int ai[maxn];
int main()
{
    //freopen("dd.txt","r",stdin);
    int n,m;
    while(scanf("%d",&m)!=EOF)
    {
        int i,j;
        for(i=0;i<num[m];i++)
        {
            for(j=0;j<num[m];j++)
            scanf("%lf",&map[i][j]);
        }
        scanf("%d",&n);
        for(i=1;i<=n;i++)
        scanf("%d",&ai[i]);
        for(i=0;i<=n;i++)
        for(j=0;j<=num[m];j++)
        dp[i][j]=0;
        for(j=0;j<num[m];j++)
        dp[n+1][j]=1.0;
        for(i=n;i>=1;i--)
        {
            for(j=0;j<num[m];j++)
            {
                dp[i][j]=map[j][ai[i]]*max(dp[i+1][j],dp[i+1][ai[i]]);
            }
        }
        double ans=0;
        for(i=0;i<num[m];i++)
        ans=max(ans,dp[1][i]);
        printf("%.6lf\n",ans);
    }
    return 0;
}



  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值