How many hdu 1799 cycles?

Source: Internet
Author: User

How many cycles?
Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission (s): 2096 Accepted Submission (s): 755

 

Problem Description
We know that in programming, we often need to consider the time complexity, especially for the loop. 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
There are T group cases, T <= 10000. Each case has two integers, m and n, 0 <m <= 2000, 0 <n <=.
 


Output
For each case, output a value, indicating the total calculation amount. Maybe this number is large, you only need to output the remainder except 1007.
 


Sample Input
2
1 3
2 3


Sample Output
3
3. This question is a bit of a dynamic planning taste. It is based on the former, and the poor status is transferred.
0 1 2 3 4
1 1 1 1
2 0 1 2 3
3 0 0 1 3
4 0 0 0 1

See the table does not, according to the table unfortunately concluded that the number of j in the I layer has dp [I] [j] = dp [I] [J-1] + dp [I-1] [J-1]
[Cpp] view plaincopyprint? # Include <iostream>
# Include <cstdio>
# Include <cstring>
Using namespace std;
# Define N 2001
# Define M 1007
Int f [N] [N];
Int main (){
Int I, j, n, m, T;
For (I = 1; I <N; I ++) f [1] [I] = 1;
For (I = 2; I <N; I ++) // layer I
For (j = I; j <N; j ++) {// Number of j
F [I] [j] = f [I] [J-1] + f [I-1] [J-1];
If (f [I] [j]> = M) f [I] [j] % = M;
}
Scanf ("% d", & T );
While (T --){
Scanf ("% d", & m, & n );
For (I = m, j = 0; I <= n; I ++ ){
J + = f [m] [I];
If (j> = M) j % = M;
}
Printf ("% d \ n", j );
}
 
Return 0;
}

# Include <iostream>
# Include <cstdio>
# Include <cstring>
Using namespace std;
# Define N 2001
# Define M 1007
Int f [N] [N];
Int main (){
Int I, j, n, m, T;
For (I = 1; I <N; I ++) f [1] [I] = 1;
For (I = 2; I <N; I ++) // layer I
For (j = I; j <N; j ++) {// Number of j
F [I] [j] = f [I] [J-1] + f [I-1] [J-1];
If (f [I] [j]> = M) f [I] [j] % = M;
}
Scanf ("% d", & T );
While (T --){
Scanf ("% d", & m, & n );
For (I = m, j = 0; I <= n; I ++ ){
J + = f [m] [I];
If (j> = M) j % = M;
}
Printf ("% d \ n", j );
}

Return 0;
}

 

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.