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 Apoints 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.
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. Print
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. Print
0
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.
solution -->
Lets consider there are r−1 blocks, so that, there will be r spaces to be filled (including the left of the left most block and right of the right most block). Now, n identical things should be filled in these spaces. There are n+r−1 things in that line now, which can be arranged in (n+r−1)! ways.
But, we should avoid the arrangements between the n things and r−1 blocks, since they are identical.
So, the final answer is
code-->
using namespace std ;
long long fact[100];
int p = 1000000007 ;
long long pow(long long a , int b){
long long x=1 , y=a;
while(b){
if(b%2==1){
x=x*y;
x=x%p;
}
y=y*y;
y=y%p ;
b=b/2;
}
return x ;
}
int max(int a , int b ){
return a>b?a:b ;
}
int main(){
int a,b ;
cin >> a >> b ;
fact[0]=1 ;
for(int i=1 ; i<100 ;i++)
fact[i]=(fact[i-1]*(long long)i)%p;
if( (a<25 && b<25) || abs(a-b)<2){
cout <<"0";
return 0 ;
}
if(a>=24 && b>=24){
if(abs(a-b)!=2){
cout <<"0";
return 0 ;
}
int z =max(a,b)-2;
z=z-24;
long long q= (fact[24]*fact[24])%p ;
long long ans =(fact[24+25-1]*pow(q,p-2))%p;
long long zz=pow(2,z);
ans=(ans*zz)%p;
cout << ans << endl ;
return 0 ;
}
int y;
if(a>b)
y=b;
else
y=a;
long long z = (fact[y]*fact[25-1])%p ;
long long ans=(fact[25+y-1]*pow(z,p-2))%p;
cout << ans << endl ;
return 0 ;
}
No comments:
Post a Comment