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;
}



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章