Question:
Mathematicians are able to solve Into a mythical problem. they indeed do much for the mankind. but sometimes they play trick to make some difficult problems for us to solve. the equation problem is one of them. consider the equation like this: X1 + X2 +... + Xn = P, where both of n (n <= 15) and P (P <= 30) are positive integers and x1... XN are unkowns. the task is for you given n positive integers A1... an, to write a program to determine how many solutions for this kind of equation for some pair of N and P, where xi> = AI.
For example, assume the equation is X1 + X2 = 5, and A1 = 2, a2 = 2. you must calculate the number of solutions which meet the conditions: x1> = A1 and X2> = A2. obviously, both of X1 = 2x2 = 3 and X1 = 3x2 = 2 satisfy the conditions. and no other solution at all. so the number of total solutions is 2. you need only answer the number.
Input Specification
The input consists of M equations, the first line of input is an integer M. Then follow M equations 'descriptions, each of which is in the form of below:
N p
A1 a2...
Integers are separated by spaces.
Output Specification
For each equation, you shocould print a single line containing the number of solutions.
Solution:
Due to the question requirements, the final equation form is:
Sum for each a, including:
Subtract the two formulas to obtain the following:
This equation has appeared in composite mathematics. The number of solutions is equal to the number of r groups in multiple sets with k types of elements. The result is equal:
For this question, r is p-a and k is n.
The Code is as follows:
- # Include <cstdio>
- Int main (){
- Freopen ("in.txt", "r", stdin );
- Int m, n, p;
- Scanf ("% d", & m );
- While (M --){
- Scanf ("% d", & N, & P );
- Int A, Suma = 0;
- For (INT I = 0; I <n; I ++ ){
- Scanf ("% d", & );
- SUMA + =;
- }
- If (P = SUMA ){
- Printf ("1/N ");
- Continue;
- }
- If (P <SUMA ){
- Printf ("0/N ");
- Continue;
- }
- Int x = p-Suma + n-1, y = (p-SUMA)> (n-1 )? (N-1) :( p-SUMA );
- Double ret = 1;
- For (INT I = 0; I <Y; I ++)
- RET * = (X-I );
- For (INT I = 2; I <= y; I ++)
- RET/= I;
- Printf ("%. 0lf/N", RET );
- }
- Return 0;
- }