转眼到了收获的季节,由于有TT的专业指导,Lele获得了大丰收。特别是水果,Lele一共种了N种水果,有苹果,梨子,香蕉,西瓜……不但味道好吃,样子更是好看。
于是,很多人们慕名而来,找Lele买水果。
甚至连大名鼎鼎的HDU ACM总教头 lcy 也来了。lcy抛出一打百元大钞,"我要买由M个水果组成的水果拼盘,不过我有个小小的要求,对于每种水果,个数上我有限制,既不能少于某个特定值,也不能大于某个特定值。而且我不要两份一样的拼盘。你随意搭配,你能组出多少种不同的方案,我就买多少份!"
现在就请你帮帮Lele,帮他算一算到底能够卖出多少份水果拼盘给lcy了。
注意,水果是以个为基本单位,不能够再分。对于两种方案,如果各种水果的数目都相同,则认为这两种方案是相同的。
最终Lele拿了这笔钱,又可以继续他的学业了~
Input
本题目包含多组测试,请处理到文件结束(EOF)。
每组测试第一行包括两个正整数N和M(含义见题目描述,0<N,M<=100)
接下来有N行水果的信息,每行两个整数A,B(0<=A<=B<=100),表示至少要买该水果A个,至多只能买该水果B个。
Output
对于每组测试,在一行里输出总共能够卖的方案数。
题目数据保证这个答案小于10^9
Sample Input
2 3 1 2 1 2 3 5 0 3 0 3 0 3
Sample Output
2 12
题解:一个母函数的模板题,想了解更多?戳 这里 !
代码如下:
#include <iostream>
#include <cstdio>
#include <stdlib.h>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <string.h>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <ctime>
#define maxn 1007
#define N 100005
#define INF 0x3f3f3f3f
#define PI acos(-1)
#define lowbit(x) (x&(-x))
#define eps 0.000000001
#define read(x) scanf("%d",&x)
#define put(x) printf("%d\n",x)
#define Debug(x) cout<<x<<" "<<endl
using namespace std;
typedef long long ll;
const double e=2.718281828459;
int n1[200],n2[200];
int a[200],b[200];
int main()
{
int m,n;
while (cin>>n>>m)
{
for(int i=0;i<n;i++)
cin>>n1[i]>>n2[i];
memset(a,0,sizeof(a));
a[0]=1;
for (int i=0;i<n;i++)
{
memset(b,0,sizeof(b));
for (int j=n1[i];j<=n2[i]&&j<=m;j++)
for (int k=0;k+j<=m;k++)
b[k+j]+=a[k];
memcpy(a,b,sizeof(b));
}
cout<<a[m]<<endl;
}
return 0;
}