HDU 2082 (母函数)

/*

可以用母函数解决;

前几天练熟了,再试试手;

*/

http://acm.hdu.edu.cn/showproblem.php?pid=2082


#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <string>
#include <iomanip>
#define maxn 1005

using namespace std;
int main(int argc, char *argv[])
{
	int word[27],a[55],b[55];
	int n;
	cin>>n;
	while(n--)
	{
		for(int i = 0; i < 26; i++)
			cin>>word[i];
		memset(a,0,sizeof(a));
		memset(b,0,sizeof(b));
		for(int i = 0; i <= word[0]; i++)
		{
			a[i] = 1;
		}
		for(int i = 1; i < 26; i++)
		{
			for(int j = 0; j <= 50; j++)
			{
				for(int k = 0,s = 0; k + j <= 50 && s <= word[i]; k += (i+1),s++)
				{
					b[k+j] += a[j];
				}
			}
			for(int j = 0; j <= 50; j++)
			{
				a[j] = b[j];
				b[j] = 0;
			}
		}
		int sum = 0;
		for(int i = 1; i <= 50; i++)
			sum += a[i];
		cout<<sum<<endl;
	}
	return 0;
}


你可能感兴趣的:(HDU 2082 (母函数))