Josephina and RPG (probability DP) ZOJ - 3735

topic

  Give a C (n, 3) the order of the matrix, each stage represents a character, the MAP [i] [j] is the probability of j i can beat, then you need to give the m order to defeat the opponent. You can choose a starting role, and you can choose whether to replace the role of the opponent, the largest winning percentage than last asks after defeat to opponents.

thought

  Defined dp [i] [j] array, i represents the first of several to hit the opponent, j represents the character selection after a game i. Can clearly know if not character replacement words, the transfer of each character is dp [i] [j] = dp [i - 1] [j] * edge [j] [a] (a i-th opponents using Character). After all, without seeking complete transformation of the role, then converted into the current role of the opponent optimum situation is to choose the best unchanged in all cases.

#include <iostream>
#include <cstring>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <queue>
#include <stack>
#include <map>
#define ull unsigned long long
#define met(a, b) memset(a, b, sizeof(a))
#define lowbit(x) (x&(-x))
#define MID (l + r) / 2
#define ll long long

using namespace std;

const int maxn = 1e4 + 7;
const ll mod = 1e6 + 3;
const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3f;

double edge[210][210];
double dp[maxn][210];

int main() {
    int n;
    while(cin >> n) {
        n = n*(n-1)*(n-2)/6;
        for(int i = 1; i <= n; i++) {
            for(int j = 1; j <= n; j++) {
                cin >> edge[i][j];
            }
        }
     //初始化边界
for(int i = 0; i <= n; i++) { dp[0][i] = 1; } int m; cin >> m; double mx; for(int i = 1; i <= m; i++) { int a; cin >> a; a++; mx = -1; for(int j = 1; j <= n; j++) { dp[i][j] = dp[i-1][j] * edge[j][a]; mx = max(mx, dp[i][j]); } dp[i][a] = mx; } printf("%.6lf\n", mx); } return 0; }

 

Guess you like

Origin www.cnblogs.com/Stay-Online/p/11333052.html