Facebook Hacker Cup Round 1---Winning at Sports

Source: Internet
Author: User
Tags cas

In the game of Sports, the object is having more points than the other team after a certain amount of time has Elap sed. Scores is denoted by and hyphen-separated integers. For example, scores may include 3-2, 4-1, or 10-0. The first number is what many points you ' ve scored, and the second are the number of points scored by the opposing team. You ' re very good at Sports, and consequently to always win. However, you don't always achieve victory the same-on-the-every time.

the The most extreme kinds of victory is called  stress-free  and < Strong>stressful . in a  stress-free  victory, you score the first point and the From then s than your opponent. in a  stressful  victory, you never has more points than your opponent until after their score I s equal to their final score.

Given The final score of a game of Sports, how many ways could your arrange the order in which the points is Scor Ed such that you secure a stress-free or stressful win?

Input

Input begins with a integer T, the number of games you ' ll play. For each game, there are one line containing the final score of the game in the format described above.

Output

For the i-th game, print a line containing ' case #I: ' followed by the space-separated integers, the numb Er of ways you can achieve a stress-free or stressful win, respectively. Since These numbers may be very large, output them modulo 1,000,000,007.

Constraints

1 ≤ T ≤100

Since you always win, the first number in any final score'll always be larger than the second. Both scores is non-negative integers not exceeding 2000.

Explanation of Sample

In the third test case, you can get a Stress-free win by scoring points 1, 2, and 4, or points 1, 2, and 3. You can get a stressful win by scoring points 2, 4, and 5, or points 3, 4, and 5.


Give a final score of the game, the front team always win the back team, there are two ways to win, two methods to find the number.

The first is that you score at the beginning, and then you always score higher than your opponent.

The second is that unless your opponent has reached the highest score, you are always lower than your opponent.

Simple DP.


 #include < Cstdio> #include <cstring>using namespace std;const int maxn=2005;const int mod=1000000007;int DP[MAXN][MAXN],    Dp2[maxn][maxn];int Main () {freopen ("Winning_at_sports.txt", "R", stdin);    Freopen ("Outc.txt", "w", stdout);    int t,cas=1,n,m,i,j;    scanf ("%d", &t);        while (t--) {scanf ("%d-%d", &n,&m);        memset (dp,0,sizeof DP);        memset (dp2,0,sizeof DP2);        Dp[0][0]=dp2[0][0]=1; for (i=0;i<=n;i++) {for (j=0;j<=m;j++) {if (i+1>j) dp[i+1][j]= (dp[i+1]                [J]+dp[i][j])%mod;                if (i>j+1) dp[i][j+1]= (dp[i][j+1]+dp[i][j])%mod; if (i+1<=j| |                j==m) dp2[i+1][j]= (dp2[i+1][j]+dp2[i][j])%mod;            if (j+1<=m) dp2[i][j+1]= (dp2[i][j+1]+dp2[i][j])%mod;    }} printf ("Case #%d:%d%d\n", cas++,dp[n][m],dp2[n][m]); } return 0;} 


Facebook Hacker Cup Round 1---Winning at Sports

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.