hdu 2082 找单词 (母函数)
http://acm.hdu.edu.cn/showproblem.php?pid=2082 题意:26个字母,第i个字母有x[i]个,价值为i.问能组成多少个价值不超过50的单词(注意这里的单词只考虑字母的组成,不考虑字母之间的顺序) 思路:母函数。
1/* ***********************************************
2Author :111qqz
3Created Time :2016年02月27日 星期六 15时56分31秒
4File Name :code/hdu/2082.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=1E4;
34LL a[N],tmp[N];
35int x[N];
36int n;
37int main()
38{
39 #ifndef ONLINE_JUDGE
40 freopen("code/in.txt","r",stdin);
41 #endif
42
43
44 ios::sync_with_stdio(false);
45 int T;
46 cin>>T;
47 while (T--)
48 {
49 for ( int i = 1; i <= 26 ; i ++) cin>>x[i];
50
51 ms(tmp,0);
52 ms(a,0);
53 for ( int i = 0 ; i <= x[1]; i++)
54 {
55 a[i] = 1;
56 }
57 // cout<<"aaa"<<endl;
58 int cur = x[1]*1;
59 for ( int i = 2 ; i <= 26 ; i++)
60 {
61 for ( int j = 0 ; j<= cur ; j++)
62 {
63 for ( int k = 0 ; k <= x[i] ; k++)
64 {
65 tmp[j+i*k]+=a[j];
66 }
67 }
68
69 cur += x[i]*i;
70
71 // cout<<"bbb:"<<endl;
72
73 for ( int j = 0 ; j <= cur ; j++)
74 {
75 a[j] = tmp[j];
76 tmp[j] = 0 ;
77 }
78 }
79 // cout<<"asdsad"<<endl;
80 LL ans = 0LL ;
81 for ( int j = 1 ; j <= 50 ; j++)
82 {
83 ans += a[j];
84 }
85 cout<<ans<<endl;
86 }
87
88 #ifndef ONLINE_JUDGE
89 fclose(stdin);
90 #endif
91 return 0;
92}