Using recursion to solve problems: EOJ2999

Source: Internet
Author: User

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

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.