[HDU 4870] Rating [DP], hdu4870rating

Source: Internet
Author: User

[HDU 4870] Rating [DP], hdu4870rating

A person registers two accounts, and the initial rating is 0. He plays the game with the low score each time. After winning the game, he adds 50 points and deducts 100 points. The winning rate is p, he will hit the game until he scored 1000 points on the first day and asked about the expectations of the game.

Question: because each time we increase or decrease the score is a multiple of 50, we can compress it into adding one point for each win and reducing the score by 2. According to the meaning, we can easily see that each score change is the smallest score.

Therefore, we define the State ans [I] [j] to indicate that the score from the initial state to the two numbers is I, j's expectation. We can know that the score change of the two numbers is always [I, I]-> [I + 1, I]-> [I + 1, I + 1]; the score of only one digit is changing at a time, which makes it easier to transfer the status. Define dp [I] to indicate the expected I + 1 score. The state transition equation is as follows:

Dp [I] = 1 × p + (1-p) * (1 + dp [I-2] + dp [I-1] + dp [I]); ans [I + 1] [I] = ans [I] [I] + dp [I], ans [I + 1] [I + 1] = ans [I + 1] [I] + dp [I];

#include <cstdio>double ans[21][21], dp[21];int main() {    double p;    int i, j;    while (~scanf("%lf", &p)) {        dp[0] = 1/p, dp[1] = 1+(1-p)/p*(dp[0]+1);        for (i = 2;i <= 19;i++) dp[i] = 1+(1-p)/p*(dp[i-2]+dp[i-1]+1);        ans[0][0] = 0,ans[1][0] = dp[0],ans[1][1] = ans[1][0]+dp[0];        for (i = 1;i <= 19;i++) {            ans[i+1][i] = ans[i][i]+dp[i];            ans[i+1][i+1] = ans[i+1][i]+dp[i];        }        printf("%.6lf\n", ans[20][19]);    }}



Acm hdu 2412 tree DP

Lzsb output Yes No, not YES NO

HDU3646 DP Solution Why WA?

Consider M> N! There is also a boundary of 0 birds and 0 monsters!
# Include <iostream>
Using namespace std;
Const int NN = 11000;
Int mn (int x, int y) {if (x <y) return x; return y ;}
Int f [NN] [102], g [NN] [102], B [NN], ksum [NN * 10];
Int main ()
{
// Freopen ("in.txt", "r", stdin );
Int pt, I, j, x, N, M, K, gg, tgg, ed, ted;
While (scanf ("% d", & N, & M, & K), N + M + K ){
For (I = 1; I <= N; I ++ ){
Scanf ("% d", & x); B [I] = x;
}
For (ksum [0] = 0, I = 1; I <= K; I ++ ){
Scanf ("% d", & x );
Ksum [I] = ksum [I-1] + x;
}
F [0] [0] = g [0] [0] = 0;

For (I = 1; I <= N; I ++ ){
For (j = 0; j <= mn (I, M); j ++ ){
Ed = ted =-1;
If (J-1> = 0 & I-1> = J-1 ){
Int st = f [I-1] [J-1];
Pt = B [I] * 2 + g [I-1] [J-1];
Ed = st;
While (ed + 1 <= K & ksum [ed + 1] <= pt ){
Ed ++;
If (ksum [ed] = pt) break;
}
If (ed = st ){
Gg = pt;
} Else gg = ksum [ed];
}
If (I-1> = j ){
Int st = f [I-1] [j];
Pt = B [I] + g [I-1] [j];
Ted = st;
While (ted + 1 <= K & ksum [ted + 1] <= pt ){
Ted ++;
If (ksum [ted] = pt) break;
}
If (ted = st ){
Tgg = pt;
} Else tgg = ksum [ted];
}
If (ted> ed | (ted = ed & tgg> gg) {gg = tgg, ed = ted ;}
F [I] [j] = ed; g [I] [j] = gg;
// Printf ("% d", f [I] [j]);
} // Printf ("\ n ");
} // Printf ("\ n ");
For (j =-1, I = 0; I <= M; I ++) if (j <f [N] [I]) j = f [N] [I];
Printf ("% d \ n", j );
}
Return 0;
}... Remaining full text>

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.