Facebook Hacker Cup 2015 Round 1 --- Winning at Sports

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

The two most extreme kinds of victory are called stress-free and stressful. In a stress-free victory, you score the first point and from then on you always have more points than your opponent. In a stressful victory, you never have more points than your opponent until after their score is equal to their final score.

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

Input

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

Output

For the ith game, print a line containing "Case #i: " followed by two space-separated integers, the number 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 will always be larger than the second. Both scores will be 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.


给一个比赛的最终得分,前面的队总是赢了后面的队,有两种赢的方法,求两种方法数。

第一种是,最开始由你得分,此后你的得分总是比对手高。

第二种是,除非你的对手已经达到最高分了,你总是比你的对手分低。

简单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;
}


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值