DP ZOJ 3735 Josephina and RPG

Source: Internet
Author: User

Topic Portal

Test instructions: Tell you C (m,3) a team between each other's winning percentage, and then you want to play against N AI team, the first choice of a team, and then overcome an AI can choose to replace the AI team, you can also do not change, ask you the last biggest winning percentage is how much.

Analysis: DP[I][J][0/1] represents the first AI, with the ID of J to attack, this J can be the ID of the previous state exchange AI or not, the state transition equation:

Dp[i][j][0] = max (dp[i-1][j][0], dp[i-1][j][1]) * P[j][a[i]];
if (i > 1)
DP[I][A[I-1]][1] = max (dp[i][a[i-1]][1], Max (dp[i-1][j][0], dp[i-1][j][1]) * P[a[i-1]][a[i]]);

Efficiency is not very high ...

/************************************************* author:running_time* Created time:2015/10/24 Saturday 13:32:44* Fi Le name:j.cpp ************************************************/#include <cstdio> #include <algorithm># Include <iostream> #include <sstream> #include <cstring> #include <cmath> #include <string > #include <vector> #include <queue> #include <deque> #include <stack> #include <list># Include <map> #include <set> #include <bitset> #include <cstdlib> #include <ctime>using namespace std; #define Lson L, Mid, RT << 1#define Rson mid + 1, R, RT << 1 | 1typedef long ll;const int N = 1e4 + 10;const int INF = 0x3f3f3f3f;const int MOD = 1e9 + 7;const Double EPS = 1e-8;do    Uble dp[n][122][2];d ouble p[122][122];int a[n];int Main (void) {int m, r, N;        while (scanf ("%d", &m) = = 1) {if (M = = 3) R = 1;        else if (m = = 4) R = 4; else if (m = = 5)    R = 10;        else if (m = = 6) R = 20;        else if (m = = 7) R = 35;        else if (m = = 8) R = 56;        else if (m = = 9) R = 84;        else if (m = = Ten) R = 120;            for (int. I=1; i<=r; ++i) {for (int j=1; j<=r; ++j) {scanf ("%lf", &p[i][j]);        }} scanf ("%d", &n);    for (int i=1; i<=n; ++i) {scanf ("%d", &a[i]);        a[i]++;        } memset (DP, 0, sizeof (DP));        for (int i=1; i<=r; ++i) dp[0][i][0] = dp[0][i][1] = 1; for (int i=1, i<=n; ++i) {for (int j=1; j<=r; ++j) {dp[i][j][0] = max (dp[i-1][j][                0], dp[i-1][j][1]) * P[j][a[i]; if (i > 1) dp[i][a[i-1]][1] = max (dp[i][a[i-1]][1], Max (dp[i-1][j][0], dp[i-1][j][1]) * p[a[i-1]][            A[i]]);        }} double ans = 0; for (int i=1; i<=r; ++i) ans = max (ans, Max (dp[n][i][0], dp[n][i)[1]));    printf ("%.6f\n", ans); } return 0;}

  

DP ZOJ 3735 Josephina and RPG

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.