HDU 2152__ Parent function

Source: Internet
Author: User
Fruit Time limit:1000/1000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): 4460 accepted Submission (s): 2570


Problem Description blink of an eye to the harvest season, because there are TT professional guidance, Lele obtained a bumper harvest. Especially fruit, lele a total of n kinds of fruit, there are apples, pears, bananas, watermelon ... Not only the taste is delicious, the appearance is more good-looking.

So, many people come to Lele to buy fruit.

Even the famous HDU ACM Chief Instructor LCY also came. LCY throws a dozen hundred dollar bills, "I want to buy a fruit platter consisting of M fruit, but I have a small request, for each fruit, I have a limit on the number, can not be less than a certain value, and can not be greater than a certain value." And I don't want two copies of the same platter. How many different options can I buy if you are free to go with it? "

Now please help Lele, help him calculate how many copies of the fruit can sell the platter to LCY.

Note that fruit is a basic unit and cannot be divided. For both schemes, if the number of fruits is the same, the two schemes are considered to be the same.

Finally Lele took the money, and can continue his studies ~

Input This topic contains multiple sets of tests, please process to file end (EOF).
The first row of each group of tests consists of two positive integers N and M (meaning see topic Description, 0<N,M<=100)
Next there is the information of n rows of fruit, two integers per line a,b (0<=a<=b<=100), which means at least buy the fruit a, and at most can buy the fruit B.

Output for each set of tests, the total number of scenarios that can be sold in a single line.
Problem data Guarantee This answer is less than 10^9

Sample Input
2 3 1 2 1 2 3 5 0 3 0 3 0-3
Sample Output
2 12

This problem once again taught me a truth, to carefully read the question Qaq. The topic meaning is gives you n fruit, each kind of fruit has innumerable, requests just buys the M a fruit, asks how many kind of plan, notices, here also has one condition limit is each kind of plan must satisfy each kind of fruit the purchase quantity to satisfy certain scope. Obviously, the template of the parent function can be applied to each kind of fruit as a different type of 1g weight.

Code:

#include <iostream>
#include <cstring>
using namespace std;
#define MAXN
int n,m;
int c1[105],c2[105];
int l[105],r[105];
int main () {
    int i,j,k,kk,sum;
    while (cin>>n>>m) {
          memset (c1,0,sizeof (C1));
          memset (c2,0,sizeof (C2));
          sum=0;
          C1[0]=1;
          for (i=1;i<=n;i++) cin>>l[i]>>r[i];
          for (i=1;i<=n;i++)
          {
           //if (l[i]==0) l[i]=1;
           for (j=0;j<=m;j++) for
           (k=l[i];k<=r[i]&&k+j<=m;k++)//Note here is not starting from 0, but starting from the left range of the corresponding fruit
           {
            C2[K+J]+=C1[J];
           cout<<j<< "" <<k<< "" <<c2[k*j]<<endl;
           }
           for (kk=0;kk<=m;kk++) {c1[kk]=c2[kk];c2[kk]=0}}
          cout<<c1[m]<<endl;
    }
    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.