hdu 2152 Fruit (母函数)
http://acm.hdu.edu.cn/showproblem.php?pid=2152
题意:中文题目,大概是说有n(<=100)种水果,第i种至少拿l[i]个,最多拿r[i]个,现在挑选m种水果组成一个果盘,问方案数。
思路:母函数,之前的题目都是只对上界有限制,其实对下界有限制是一样的。以及。。。一开始以为是拿100元买。。。后来发现是“一打百元大钞”23333 其实再出难点可以对个数以及钱数都有限制。。。。
/* ***********************************************
Author :111qqz
Created Time :2016年02月27日 星期六 15时14分12秒
File Name :code/hdu/2152.cpp
************************************************ */
1#include <cstdio>
2#include <cstring>
3#include <iostream>
4#include <algorithm>
5#include <vector>
6#include <queue>
7#include <set>
8#include <map>
9#include <string>
10#include <cmath>
11#include <cstdlib>
12#include <ctime>
13#define fst first
14#define sec second
15#define lson l,m,rt<<1
16#define rson m+1,r,rt<<1|1
17#define ms(a,x) memset(a,x,sizeof(a))
18typedef long long LL;
19#define pi pair < int ,int >
20#define MP make_pair
1using namespace std;
2const double eps = 1E-8;
3const int dx4[4]={1,0,0,-1};
4const int dy4[4]={0,-1,1,0};
5const int inf = 0x3f3f3f3f;
6const int N=105;
7int a[N],tmp[N];
1int n,m;
2int l[N],r[N];
3int main()
4{
5 #ifndef ONLINE_JUDGE
6 freopen("code/in.txt","r",stdin);
7 #endif
1 while (~scanf("%d %d",&n,&m))
2 {
3 for ( int i = 1 ; i <= n ; i++) scanf("%d %d",&l[i],&r[i]);
ms(tmp,0);
ms(a,0);
1 for ( int i = l[1] ; i <= r[1] ; i++ )
2 {
3 a[i] = 1;
4 }
1 for ( int i = 2 ; i <= n ; i++)
2 {
3 for ( int j = 0 ; j <= m ; j++)
4 {
5 for ( int k = l[i] ; k <= r[i] ; k++ )
6 {
7 tmp[j+k] +=a[j];
8 }
9 }
1 for ( int j = 0 ; j <= m ; j++)
2 {
3 a[j] = tmp[j];
4 tmp[j] = 0 ;
5 }
6 }
printf("%d\n",a[m]);
}
1 #ifndef ONLINE_JUDGE
2 fclose(stdin);
3 #endif
4 return 0;
5}