Facebook Hacker Cup Round 1--winning at Sports (Dynamic planning)

Source: Internet
Author: User

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)

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.