2 3 1 2 1 2 3 5 0 3 0 3 0 3
2 12
简单母函数。
代码:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>
using namespace std;
const int M = 1e5+10;
int c1[101], c2[101];
int x[M], y[M];
int main(){
int n, m;
while(cin >> n >> m){
for(int i = 0; i < n; ++ i)
cin >> x[i] >> y[i];
memset(c1, 0, sizeof(c1));
memset(c2, 0, sizeof(c2));
c1[0] = 1;
for(int i = 0; i < n; ++ i){
for(int j = x[i]; j <= y[i]&&j <= m; ++ j){
for(int k = 0; k+j <= m; ++ k){
c2[k+j] += c1[k];
}
}
for(int j = 0; j <= m; ++ j){
c1[j] = c2[j]; c2[j] = 0;
}
}
cout << c1[m]<<endl;
}
return 0;
}原文:http://blog.csdn.net/shengweisong/article/details/44539313