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;
}
时间: 2024-12-21 01:11:13

Facebook Hacker Cup 2015 Round 1 --- Winning at Sports的相关文章

Facebook Hacker Cup 2015 Round 1 Winning at Sports (附带测试数据)

题目描述: Winning at Sports25 points 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 1

Facebook Hacker Cup 2015 Round 1--Corporate Gifting(树形动态规划)

原题:https://www.facebook.com/hackercup/problems.php?pid=759650454070547&round=344496159068801 题意:给定一颗有根树,在树上下层的节点要给上层节点礼物,根节点的礼物则给慈善会,但是给礼物有个条件就是你不能送你的父节点已经送出的礼物.问满足要求的最少花费. 题解:这个题卡了一段时间,类似于染色问题,可以用树形动态规划求解.因为已知节点个数为N,则我们单个节点的最大花费不会超过log2(N) = 18. 1.

Facebook Hacker Cup 2015 Round 1--Winning at Sports(动态规划)

原题:https://www.facebook.com/hackercup/problems.php?pid=688426044611322&round=344496159068801 题意:你和一个朋友玩足球游戏,分数从0-0开始,最终你总是赢,并且你主要有两种方式赢,第一种stressFree方式你肯定要进第一个球并且总是比你的朋友分数高,第二种stressFull方式除了你的朋友达到最终分数时,在游戏中你不可能比你的朋友分数高.给出一个比分,请分别输出在两种情况下你能赢的方式. 题解:类似

Facebook Hacker Cup 2015 Round 1 Homework(附带测试数据)

题目描述: Homework10 points Your first-grade math teacher, Mr. Book, has just introduced you to an amazing new concept - primes! According to your notes, a prime is a positive integer greater than 1 that is divisible by only 1 and itself. Primes seem fun

Facebook Hacker Cup 2015 Round 1 Autocomplete (附带测试数据)

题目描述: Autocomplete25 points Since you crave state-of-the-art technology, you've just purchased a phone with a great new feature: autocomplete! Your phone's version of autocomplete has some pros and cons. On the one hand, it's very cautious. It only a

Facebook Hacker Cup 2015 Round 1--Autocomplete(字典树新建与查询)

题意:给定N个字符串,让你依次先输入到手机的字典中,再打印出来,打印的时候我们只需要输出字符串的前缀或者全部字符串,要求此前缀不是以往任何字符串的前缀. 题解:典型的字典树,可以利用结构体数组方便的新建与查询,速度比链表更快.只需在插入字符串时统计最长相同的前缀即可. 代码如下: #include<cstdio> #include<cstring> #include<algorithm> using namespace std; #define maxN 1000005

Facebook Hacker Cup 2015 Round 1--Homework(筛选法求素数)

题意:给定A,B,K(A<=B)三个数,问在[A,B]范围内的数素数因子个数为K的个数. 题解:典型的筛选法求素数.首先建立一个保存素数因子个数的数组factorNum[],以及到n为止含有素数因子个数为k的二维数组sumNum[n][k]. factorNum可以由筛选法确定,初始化数组为0. 1. 从小到大遍历给定最大范围内的数,若遍历到数n时,factorNum[n]=0则说明这个数是素数(前面没有它的因子). 2. 然后通过增加n的倍数,来筛选出最大范围内含有素数因子n的数. sumNu

Facebook Hacker Cup 2015 Round 1 --- Homework

给一个区间,求该区间内 质因子个数等于k的数 的个数. 暴力预处理一下啦 #include<cstdio> #include<cstring> using namespace std; const int maxn=10000010; bool pri[maxn]; int cnt[maxn]; void init() { memset(pri,1,sizeof pri); memset(cnt,0,sizeof cnt); for(int i=2;i<=10000000;i

Facebook Hacker Cup 2015 Round 1 --- Autocomplete

Since you crave state-of-the-art technology, you've just purchased a phone with a great new feature: autocomplete! Your phone's version of autocomplete has some pros and cons. On the one hand, it's very cautious. It only autocompletes a word when it