HDU 2152
生成函数简单题
#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #define N 110 using namespace std; struct Fruit{ int a,b; }; Fruit num[N]; int c1[N],c2[N]; int main(){ int n,m; while(scanf("%d%d",&n,&m)!=EOF){ for(int i=1;i<=n;i++) scanf("%d%d",&num[i].a,&num[i].b); memset(c1,0,sizeof(c1)); memset(c2,0,sizeof(c2)); for(int i=num[1].a;i<=num[1].b;i++) c1[i]=1; for(int i=2;i<=n;i++){ for(int j=0;j<N;j++){ for(int k=num[i].a;k<=num[i].b&&k+j<N;k++) c2[k+j]+=c1[j]; } for(int j=0;j<N;j++) c1[j]=c2[j],c2[j]=0; } printf("%d\n",c1[m]); } return 0; }