hdu 2152 Fruit (母函数)
http://acm.hdu.edu.cn/showproblem.php?pid=2152
题意:中文题目,大概是说有n(<=100)种水果,第i种至少拿l[i]个,最多拿r[i]个,现在挑选m种水果组成一个果盘,问方案数。
思路:母函数,之前的题目都是只对上界有限制,其实对下界有限制是一样的。以及。。。一开始以为是拿100元买。。。后来发现是“一打百元大钞”23333 其实再出难点可以对个数以及钱数都有限制。。。。
1/* ***********************************************
2Author :111qqz
3Created Time :2016年02月27日 星期六 15时14分12秒
4File Name :code/hdu/2152.cpp
5************************************************ */
6
7#include <cstdio>
8#include <cstring>
9#include <iostream>
10#include <algorithm>
11#include <vector>
12#include <queue>
13#include <set>
14#include <map>
15#include <string>
16#include <cmath>
17#include <cstdlib>
18#include <ctime>
19#define fst first
20#define sec second
21#define lson l,m,rt<<1
22#define rson m+1,r,rt<<1|1
23#define ms(a,x) memset(a,x,sizeof(a))
24typedef long long LL;
25#define pi pair < int ,int >
26#define MP make_pair
27
28using namespace std;
29const double eps = 1E-8;
30const int dx4[4]={1,0,0,-1};
31const int dy4[4]={0,-1,1,0};
32const int inf = 0x3f3f3f3f;
33const int N=105;
34int a[N],tmp[N];
35
36int n,m;
37int l[N],r[N];
38int main()
39{
40 #ifndef ONLINE_JUDGE
41 freopen("code/in.txt","r",stdin);
42 #endif
43
44
45 while (~scanf("%d %d",&n,&m))
46 {
47 for ( int i = 1 ; i <= n ; i++) scanf("%d %d",&l[i],&r[i]);
48
49
50 ms(tmp,0);
51 ms(a,0);
52
53 for ( int i = l[1] ; i <= r[1] ; i++ )
54 {
55 a[i] = 1;
56 }
57
58 for ( int i = 2 ; i <= n ; i++)
59 {
60 for ( int j = 0 ; j <= m ; j++)
61 {
62 for ( int k = l[i] ; k <= r[i] ; k++ )
63 {
64 tmp[j+k] +=a[j];
65 }
66 }
67
68 for ( int j = 0 ; j <= m ; j++)
69 {
70 a[j] = tmp[j];
71 tmp[j] = 0 ;
72 }
73 }
74
75
76 printf("%d\n",a[m]);
77
78
79
80
81 }
82
83 #ifndef ONLINE_JUDGE
84 fclose(stdin);
85 #endif
86 return 0;
87}