HDU 1799 cycles How many times? (Dp+ combinatorial mathematics)

Source: Internet
Author: User

How many times are the loops? Time limit:3000/1000 MS (java/others) Memory limit:65536/32768 K (java/others)
Total submission (s): 3984 Accepted Submission (s): 1513


problem Descriptionwe know that in programming, we often need to take into account the complexity of time, especially for the loop part. For example
If the code appears
for (i=1;i<=n;i++) OP;
Then do the N-Times op operation if the code appears
fori=1;i<=n; i++)
for (j=i+1;j<=n; j + +) OP;
Then do N (n-1)/2 op operation.
Now you are given an M-layer for loop operation, and each time the start value of the variable in for is the starting value of the previous variable +1 (the first variable starts with a value of 1), the terminating value is an input n, and the last OP has a total amount of computation.
 InputThere are T group case,t<=10000. Each case has two integers m and n,0<m<=2000,0<n<=2000.
Outputfor each case, output a value that represents the total amount of computation, perhaps the number is large, then you only need to output the remainder of the 1007 left.
Sample Input
21 32 3

Sample Output
33

AuthorWangye
Source"Insigma International Cup" Zhejiang Collegiate Programming Contest-warm up (4)
The problem: This topic uses the permutation combination C (m,n)(that is, from the n elements in any of the M elements) thinking way, the implementation process with the Yang Hui triangle (because the value of the Yang Hui Triangle can be 1007 and save). now explain why this problem is related to permutations: Suppose there are now 4 balls a B C D to take 2 from. By arranging the combination of the way: First take A and then take B c D, then take B and then take C D; then C can take the remaining d so that there is 3 + 2 + 1 = 6 combinations. Here's 4 is the title of n here's 2 is the topic of m (number of cycles);if the number of cycles is 3 then take a and then B and then take C D;so the number of questions asked how many ways to get the ball: C (m,n) ==c (m-1,n-1) +c (m-1,n); That is the Yang Hui triangle.
AC Code: 
#include <iostream> #include <cstdlib> #include <cstdio> #include <cmath> #include <cstring > #include <string> #include <cstdlib> #include <iomanip> #include <algorithm> #include < Time.h>typedef Long Long ll;using namespace Std;int arr[2005][2005];int main () {int t,i,j;scanf ("%d", &t); for (I=1 ; i<=2002;i++) {arr[i][i]=1;  C (i,i) arr[i][0]=0;  

HDU 1799 cycles How many times? (Dp+ combinatorial mathematics)

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.