原题链接:HDU's ACM 2152 Fruit
分析:母函数大法好!参考:HDU's ACM 1028 Ignatius and the Princess III,变化就在于范围,设某种水果的数量范围为 [Min, Max],则对应的因式为(x^Min+x^(Min+1)+...+x^Max),无其他难点。
AC Code
<span style="font-family:Microsoft YaHei;font-size:14px;">#include <stdio.h>
#include <string.h>
#define MAXN 100
#define MAXM 100+10
typedef struct {
int min;
int max;
} Range;
Range rangeArr[MAXN];
int coeff1[MAXM];
int coeff2[MAXM];
int main()
{
int n, m;
int i, j, k;
while(scanf("%d%d", &n, &m) == 2){
memset(rangeArr, 0, sizeof(int)*MAXN);
memset(coeff1, 0, sizeof(int)*MAXM);
memset(coeff2, 0, sizeof(int)*MAXM);
for(i=0;i<n;++i){
scanf("%d%d", &rangeArr[i].min, &rangeArr[i].max);
}
for(i=rangeArr[0].min;i<=rangeArr[0].max && i<=m;++i)
coeff1[i] = 1;
for(i=1;i<n;++i){
for(j=0;j<=m;++j)
for(k=rangeArr[i].min;k<=rangeArr[i].max && (j+k)<=m;++k)
coeff2[j+k] += coeff1[j];
memcpy(coeff1, coeff2, sizeof(int)*MAXM);
memset(coeff2, 0, sizeof(int)*MAXM);
}
printf("%d\n", coeff1[m]);
}
return 0;
}</span>