2016HUAS_ACM Summer Camp 4 A-recursion

Source: Internet
Author: User

Use the combination formula C (n,m) =c (n-1,m) +c (n-1,m-1). That is, from the number of N to select the number of M, in an incremental way in each layer of the loop.

Yang Hui triangle + two-term theorem, there is really a "meaning" of a problem. To tell the truth, not original. Excuse me.....

The main idea: a cyclic structure has m-layer, the first layer is 1~n, after each additional layer, the initial value of the cyclic variables are added 1 on the basis of the previous layer.

For example: The first layer is 1~n, then the second layer is 2~n, and so on. Find the number of cycles of the M layer (answer to 1007 modulo).

Sample Input

2//Number of test cases T

1 3//m and N

2 3

Sample Output//Cycle times

3

3

#include <iostream>#include<cstdio>using namespacestd;intt,m,n,i,j;intans[2001][2001];voidSlove () {ans[0][0]=1;  for(i=1; i<= -; i++) {ans[i][0]=1;  for(j=1; j<= -; j + +) Ans[i][j]= (ans[i-1][j-1]+ans[i-1][J])%1007; }   }intMain () {slove (); CIN>>T;  while(t--) {cin>>m>>N; printf ("%d\n", Ans[n][m]); }        return 0;} 

2016HUAS_ACM Summer Camp 4 A-recursion

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.