Tatyana is a big sports fan and she likes volleyball a lot! She writes down the final scores of the game after it has ended in her notebook.
If you are not familiar with the rules of volleyball, here's a brief:
- 2 teams play in total
- During the course of the game, each team gets points, and thus increases its score by 1.
- The initial score is 0 for both teams.
The game ends when
- One of the teams gets 25 points and another team has < 24 points ( strictly less than 24).
- If the score ties at 24:24, the teams continue to play until the absolute difference between the scores is 2.
Given the final score of a game in the format A:*B* i.e., the first team has scored A points and the second has scored B points, can you print the number of different sequences of getting points by teams that leads to this final score?
Input Format
The first line contains A and the second line contains B.Constraints
0 ≤ A , B ≤ 109
Output Format
Output the number of different sequences of getting points by the teams that leads to the final score A : B. Final means that the game should be over after this score is reached. If the number is larger than 109+7, output number modulo 109 + 7. Print0
if no such volleyball game ends with the given score.Example input #00
3 25
Example output #00
2925
Example input #01
24 17
Example output #01
0
Explanation #01
There's no game of volleyball that ends with a score of 24 : 17.
题目大意:给出一局排球比赛的比分,求有多少种方式得到这个比分。。
知识点:组合数学
Accepted Code:
1 #include <iostream>
2 using namespace std;
3
4 typedef long long LL;
5 const int MOD = 1e9 + 7;
6 LL c[50][25];
7
8 LL powMod(int a, int b, int c) {
9 LL res = 1;
10 while (b) {
11 if (b & 1) res = (res * a) % c;
12 a = (LL)a * a % c;
13 b >>= 1;
14 }
15 return res;
16 }
17
18 void init() {
19 c[0][0] = 1;
20 for (int i = 1; i < 50; i++) {
21 c[i][0] = 1; c[i - 1][i] = 0;
22 for (int j = 1; j <= i; j++) {
23 c[i][j] = ((LL)c[i - 1][j] + c[i - 1][j - 1]) % MOD;
24 }
25 }
26 }
27
28 int main(void) {
29 init();
30 int n, m;
31 while (cin >> n >> m) {
32 if (n > m) swap(n, m);
33 if (m < 25 || m == 25 && m - n < 2) {cout << "0" << endl; continue;}
34 if (m > 25 && m - n != 2) {cout << "0" << endl; continue;}
35 if (m == 25) {
36 cout << c[24 + n][n] << endl;
37 } else {
38 cout << ((LL)c[48][24] * powMod(2, n - 24, MOD)) % MOD << endl;
39 }
40 }
41 return 0;
42 }