转眼到了收获的季节,由于有TT的专业指导,Lele获得了大丰收。特别是水果,Lele一共种了N种水果,有苹果,梨子,香蕉,西瓜……不但味道好吃,样子更是好看。
于是,很多人们慕名而来,找Lele买水果。
甚至连大名鼎鼎的HDU ACM总教头 lcy 也来了。lcy抛出一打百元大钞,“我要买由M个水果组成的水果拼盘,不过我有个小小的要求,对于每种水果,个数上我有限制,既不能少于某个特定值,也不能大于某个特定值。而且我不要两份一样的拼盘。你随意搭配,你能组出多少种不同的方案,我就买多少份!”
现在就请你帮帮Lele,帮他算一算到底能够卖出多少份水果拼盘给lcy了。
注意,水果是以个为基本单位,不能够再分。对于两种方案,如果各种水果的数目都相同,则认为这两种方案是相同的。
最终Lele拿了这笔钱,又可以继续他的学业了~
0 < n , m ≤ 100 , 0 ≤ A ≤ B ≤ 100 0<n,m≤100,0≤A≤B≤100 0<n,m≤100,0≤A≤B≤100
input
2 3
1 2
1 2
3 5
0 3
0 3
0 3
output
2
12
code
//Siberian Squirrel
//#include<bits/stdc++.h>
#include<unordered_map>
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cmath>
#define ACM_LOCAL
using namespace std;
typedef long long ll;
const double PI = acos(-1);
const double eps = 1e-7;
const int MOD = 3221225473;
const int N = 3e4 + 10;
const int UP = 17;
ll f1[N], f2[N];
int l, r;
inline ll solve(int n, int m, ll res = 0) {
memset(f1, 0, sizeof(ll) * (m + 1));
f1[0] = 1;
for(int i = 1; i <= n; ++ i) {
scanf("%d%d", &l, &r);
for(int j = 0; j <= m; ++ j) {
for(int k = l; k <= r && k + j <= m; ++ k) {
f2[k + j] += f1[j];
}
}
for(int j = 0; j <= m; ++ j) {
f1[j] = f2[j];
f2[j] = 0;
}
}
return f1[m];
}
int main() {
#ifdef ACM_LOCAL
freopen("input", "r", stdin);
freopen("output", "w", stdout);
#endif
int o = 1, n, m;
// scanf("%d", &o);
while(o --) {
while(~scanf("%d%d", &n, &m)) {
printf("%lld\n", solve(n, m));
}
}
return 0;
}