Topic:
Description
Given a polynomial (ax+by) k, calculates the coefficients of the xnym term after the expansion of the polynomial.
Input
Line 1th: An integer T (1≤t≤10) is the number of questions.
Next Total T-line. 5 integers per line, respectively, A,b,k,n,m, separated by a space between integers.
0≤k≤1,000,0≤n,m≤k, and n+m=k,0≤a,b≤1,000,000.
Output
For each issue, output a line number of questions (0 start number, format: Case #0: etc.).
Each problem is then output an integer in a row that represents the coefficients (which can be very large, and the value of the output to 10007 ).
Sample Input
3
2 5 290) 130 160
235823 382573 999) 111 888
1 1 3) 1 2
Sample Output
Case #0:
1580
Case #1:
1952
Case #2:
3
#include <stdio.h>#include<stdlib.h>Const intmo=10007;intans[1010][1010];intA,b,k,n,m,i,j,d=0;intcount;voidMain () {scanf ("%d",&count); while(count--) {scanf ("%d%d%d%d%d",&a,&b,&k,&n,&m); A=a%mo; b=b%mo; ans[0][0]=1; for(i=1; i<n+1; i++) {ans[i][0]=a*ans[i-1][0]%mo; } for(j=1; j<m+1; j + +) {ans[0][j]=b*ans[0][j-1]%mo; } for(i=1; i<n+1; i++){ for(j=1; j<m+1; j + +) {Ans[i][j]= (a*ans[i-1][j]+b*ans[i][j-1])%mo; }} printf ("Case #%d:\n%d\n", d++, Ans[n][m]); }}
At first I wanted to do it with a recursive return but timed out.
intccintKintN) { intresult=0; if(k==0|| k==N) {result=1; returnresult; } Else{result= (CC (k,n-1) +CC (K-1, N-1))%10007; returnresult; }}
Using recursion to solve problems: EOJ2999