【題目大意】:給出n種水果,從中選m個,其中每種水果要求不少於x個且不多於y個。問有幾種方法
【解題思路】:普通母函數,改變一下取數的範圍就可以了
【代碼】:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <cmath>
#include <string>
#include <cctype>
#include <map>
#include <iomanip>
using namespace std;
#define eps 1e-8
#define pi acos(-1.0)
#define inf 1<<30
#define linf 1LL<<60
#define pb push_back
#define lc(x) (x << 1)
#define rc(x) (x << 1 | 1)
#define lowbit(x) (x & (-x))
#define ll long long
struct Node{
int x,y;
}a[110];
int c1[110],c2[110];
int n,m;
int main() {
while (~scanf("%d%d",&n,&m)){
for (int i=0; i<n; i++) scanf("%d%d",&a[i].x,&a[i].y);
memset(c1,0,sizeof(c1));
memset(c2,0,sizeof(c2));
for (int i=a[0].x; i<=a[0].y; i++) //因爲存在1這個選擇,所以0~n已經是可取的了
c1[i]=1;
for (int i=1; i<n; i++){ //枚舉可拆分的範圍
for (int j=0; j<=m; j++){ //枚舉已知的範圍
for (int k=a[i].x; j+k<=m && k<=a[i].y; k++){ //枚舉新增的範圍
c2[j+k]+=c1[j];
}
}
for (int j=0; j<=m; j++)
c1[j]=c2[j],c2[j]=0; //更新
}
cout << c1[m] << endl;
}
return 0;
}