Original question:
pid=688426044611322&round=344496159068801 ">https://www.facebook.com/hackercup/problems.php?pid= 688426044611322&round=344496159068801
Test instructions: You play football with a friend, the score starts at 0-0, and you always win. And you have two main ways to win, the first stressfree way you must be in the first ball and always higher than your friends score, another way of stressfull in addition to your friends to reach the end of the score. You can't have a higher score than your friends in the game.
Give a score. Please separately output the way you can win in both cases.
The following: similar to LCS. Because the ball can only go one by one, so give the score finally, if A:B, the last score is only likely to be a-1:b, or a:b-1.
Very easy to write the dynamic equation when stressfree.
1. Set Dp_free[i][j] As the total number of points for i:j. Obviously I > J.
2. If i = j+1, then dp_free[i][j] = dp_free[i][j-1]; If i > J+1, then dp_free[i][j] = Dp_free[i][j-1]+dp_free[i-1][j].
The same if the final score in stressfull mode is A:B, then the score is definitely caused by the b:b and all of your goals.
1. Set Dp_full[i] For your score is always no more than your friends finally score for i:j the total number of ways, obviously I <= J.
2. If i = j, then dp_full[i][j] = Dp_full[i-1][j]. If I < J. Then dp_full[i][j] = dp_full[i-1][j]+dp_full[i][j-1].
The code is as follows:
#include <cstdio>#include <cstring>#include <algorithm>using namespace STD;#define MAXN 2005#define MAXP 1000000007intDP_FREE[MAXN][MAXN];intDP_FULL[MAXN][MAXN];intDP () {memset(Dp_free,0,sizeof(Dp_free));memset(Dp_full,0,sizeof(Dp_full)); dp_free[1][0] =1; dp_full[0][0] =1; for(inti =0; i < maxn;i++) { for(intj =0; J < maxn;j++) {if(i > J) {if(J >=1) {Dp_free[i][j] = dp_free[i][j-1]; }if(I >=1&&i-1> J) {dp_free[i][j] = (dp_free[i][j]+dp_free[i-1][J])%maxp; } }Else{if(I >=1) {Dp_full[i][j] = dp_full[i-1][J]; }if(J >=1&&i <= J1) {Dp_full[i][j] = (dp_full[i][j]+dp_full[i][j-1])%maxp; } } } }return 0;}intMain () {Freopen ("Winning_at_sports.txt","R", stdin); Freopen ("Out1.txt","W", stdout);intTintb;CharC DP ();scanf("%d", &t); for(inti =1; I <= t;i++) {scanf("%d%c%d", &a,&c,&b);printf("Case #%d:%d%d\n", I,dp_free[a][b],dp_full[b][b]); }return 0;}
Facebook Hacker Cup Round 1--winning at Sports (Dynamic planning)