Fruit
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission (s): 1781 Accepted Submission (s): 1035
Problem Description
In the twinkling of an eye, Lele received a bumper harvest due to the professional guidance of TT. In particular, there are N types of fruits in Lele, including apples, pears, bananas, and watermelons ...... It not only tastes delicious, but also looks nice.
As a result, many people come here to find Lele to buy fruit.
Even the well-known hdu acm Director lcy came. Lcy throws a dozen dollar notes. "I want to buy a fruit platter consisting of M fruits, but I have a small requirement that I have a limit on the number of each fruit, which cannot be less than a specific value, it cannot be greater than a specific value. And I don't want two identical disks. If you can match them at will, I will buy as many different solutions as you can! "
Now, please help Lele and help him calculate how many fruit disks can be sold to lcy.
Note that fruit is a basic unit and cannot be further divided. For the two schemes, if the numbers of fruits are the same, the two schemes are considered to be the same.
Lele eventually took the money and can continue his studies ~
Input
This topic contains multiple groups of tests. Please process it until the end of the file (EOF ).
The first line of each group of tests contains two positive integers N and M (for meanings, see the topic description, 0 <N, M <= 100)
Next, there are N rows of fruit information. Each row has two integers, A and B (0 <= A <= B <= 100), indicating that at least one fruit is required, you can only buy up to B fruits.
Output
For each group of tests, the total number of solutions that can be sold is output in one row.
Ensure that the answer is less than 10 ^ 9
Sample Input
2 3
1 2
1 2
3 5
0 3
0 3
0 3
[Cpp]
# Include <stdio. h>
# Include <string. h>
Int max [105], min [105];
Int c1 [10050], c2 [10050];
Int main ()
{
Int n, m, I, j, k, ans;
While (scanf ("% d", & n, & m )! = EOF)
{
Ans = 0;
For (I = 1; I <= n; I ++)
{
Scanf ("% d", & min [I], & max [I]);
}
Memset (c1, 0, sizeof (c1 ));
Memset (c2, 0, sizeof (c2 ));
For (I = min [1]; I <= max [1]; I ++)
C1 [I] = 1;
For (I = 2; I <= n; I ++)
{
For (j = 0; j <= m; j ++)
For (k = min [I]; k <= max [I] & k + j <= m; k ++)
C2 [k + j] + = c1 [j];
For (j = 0; j <= m; j ++)
{
C1 [j] = c2 [j];
C2 [j] = 0;
}
}
Printf ("% d \ n", c1 [m]);
}
Return 0;
}
I personally feel that using an exponential primary function can also be used, but only a code that is unable to connect to the sample can be captured.
I personally think that's right. Why not? Please explain and paste the error code.
# Include <stdio. h>
# Include <string. h>
Int max [105], min [105];
Double c1 [10050], c2 [10050];
Double jc [105];
Void get ()
{
Int I;
Jc [0] = 1;
For (I = 1; I <= 100; I ++)
Jc [I] = jc [I-1] * I;
}
Int main ()
{
Int n, m, I, j, k, ans;
Get ();
While (scanf ("% d", & n, & m )! = EOF)
{
Ans = 0;
For (I = 1; I <= n; I ++)
{
Scanf ("% d", & min [I], & max [I]);
}
Memset (c1, 0, sizeof (c1 ));
Memset (c2, 0, sizeof (c2 ));
For (I = min [1]; I <= max [1]; I ++)
C1 [I] = 1.0/jc [I];
For (I = 2; I <= n; I ++)
{
For (j = 0; j <= m; j ++)
For (k = min [I]; k <= max [I] & k + j <= m; k ++)
C2 [k + j] + = c1 [j]/jc [k];
For (j = 0; j <= m; j ++)
{
C1 [j] = c2 [j];
C2 [j] = 0;
}
}
Printf ("%. 0lf \ n", c1 [m]);
}
Return 0;
}
Sample Output
2
12
Author
Linle
Source
ACM Program Design final examination-(3 tutorial 417)
Author: hnust_xiehonghao