hdu 2082 找单词 (母函数)
http://acm.hdu.edu.cn/showproblem.php?pid=2082 题意:26个字母,第i个字母有x[i]个,价值为i.问能组成多少个价值不超过50的单词(注意这里的单词只考虑字母的组成,不考虑字母之间的顺序) 思路:母函数。
/* ***********************************************
Author :111qqz
Created Time :2016年02月27日 星期六 15时56分31秒
File Name :code/hdu/2082.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=1E4;
7LL a[N],tmp[N];
8int x[N];
9int n;
10int main()
11{
12 #ifndef ONLINE_JUDGE
13 freopen("code/in.txt","r",stdin);
14 #endif
1 ios::sync_with_stdio(false);
2 int T;
3 cin>>T;
4 while (T--)
5 {
6 for ( int i = 1; i <= 26 ; i ++) cin>>x[i];
1 ms(tmp,0);
2 ms(a,0);
3 for ( int i = 0 ; i <= x[1]; i++)
4 {
5 a[i] = 1;
6 }
7 // cout<<"aaa"<<endl;
8 int cur = x[1]*1;
9 for ( int i = 2 ; i <= 26 ; i++)
10 {
11 for ( int j = 0 ; j<= cur ; j++)
12 {
13 for ( int k = 0 ; k <= x[i] ; k++)
14 {
15 tmp[j+i*k]+=a[j];
16 }
17 }
cur += x[i]*i;
// cout<<"bbb:"<<endl;
1 for ( int j = 0 ; j <= cur ; j++)
2 {
3 a[j] = tmp[j];
4 tmp[j] = 0 ;
5 }
6 }
7 // cout<<"asdsad"<<endl;
8 LL ans = 0LL ;
9 for ( int j = 1 ; j <= 50 ; j++)
10 {
11 ans += a[j];
12 }
13 cout<<ans<<endl;
14 }
1 #ifndef ONLINE_JUDGE
2 fclose(stdin);
3 #endif
4 return 0;
5}