HDU 1799 (How many cycles ?) (Arrangement and combination formula)

Source: Internet
Author: User
How many cycles? Time Limit: 3000/1000 MS (Java/others) memory limit: 65536/32768 K (Java/Others) Total submission (s): 3051 accepted submission (s): 1117

Problem description we know that in programming, we often need to consider the time complexity, especially for the loop part. For example,
If
For (I = 1; I <= N; I ++) OP;
N op operations are performed.
Fori = 1; I <= N; I ++)
For (j = I + 1; j <= N; j ++) OP;
Then, N * (n-1)/2 op operations are performed.
Now we know that there are m-layer for loop operations, and the starting value of each for variable is the starting value of the previous variable + 1 (the starting value of the first variable is 1 ), the end value is an input N, and the total calculation amount of the op is asked.
 
Input has T group case, T <= 10000. Each case has two integers, M and N, 0 <m <= 2000, 0 <n <=.
Output outputs a value for each case, indicating the total calculation amount. Maybe this number is large, you only need to output the remainder except 1007.
Sample Input
21 32 3
 
Sample output
33
 
Authorwangye
Source2008 "insigma International Cup" Zhejiang Collegiate Programming Contest-warm up (4) explains: 2 3 results are 3. When I is 1, there are only two possible inner loops, perform Two operations. If I is 2, perform one operation. If I is 3, do not perform a total of three operations, that is, n (n-I) in addition, I changes from 1 to n, because I see repeated parts, so the total number of times is N * (n-1)/2, which is the knowledge point of understanding the question: the permutation and combination formula C (n) M = C (N-1) (m-1) + C (m-1) code is as follows:
# Include <stdio. h> int C [2020] [2020]; // The following annotation takes m balls from N balls as an example void F () {int I, J; for (I = 1; I <2020; I ++) // initialize and copy the possibility of getting one ball to I % 1007 (this is required in the question) {c [I] [1] = I % 1007; C [I] [0] = 1; // No, it may be a} for (I = 2; I <2020; I ++) // permutation and combination formula {for (j = 1; j <2020; j ++) {c [I] [J] = (C [I-1] [J] + C [I-1] [J-1]) % 1007 ;}} int main () {int t, n, m; F (); scanf ("% d", & T); While (t --) {scanf ("% d", & M, & N); printf ("% d \ n", C [N] [m]);} return 0 ;}


HDU 1799 (How many cycles ?) (Arrangement and combination formula)

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.