Hackerrank -- Volleyball Match

Source: Internet
Author: User

Question Link

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 formatA: * B * I. e., the first team has scoredAPoints and the second has scoredBPoints, can you print the number of different sequences of getting points by teams that leads to this final score?

Input Format
The first line containsAAnd the second line containsB.

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.FinalMeans that the game shoshould be over after this score is reached. If the number is larger than 109 + 7, output number modulo 109 + 7. Print0If no such volleyball game ends with the given score.

Example input #00

325

Example output #00

2925

Example input #01

2417

Example output #01

0

Explanation #01

There's no game of Volleyball that ends with a score of 24: 17.

Question: Give the score of a volleyball match. How many ways can I get the score ..

Knowledge Point: Combined mathematics

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 }

 

Hackerrank -- Volleyball Match

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.