假设有x1个字母A, x2个字母B,..... x26个字母Z,同时假设字母A的价值为1,字母B的价值为2,..... 字母Z的价值为26。那么,对于给定的字母,可以找到多少价值<=50的单词呢?单词的价值就是组成一个单词的所有字母的价值之和,比如,单词ACM的价值是1+3+14=18,单词HDU的价值是8+4+21=33。(组成的单词与排列顺序无关,比如ACM与CMA认为是同一个单词)。
Input
输入首先是一个整数N,代表测试实例的个数。
然后包括N行数据,每行包括26个<=20的整数x1,x2,.....x26.
Output
对于每个测试实例,请输出能找到的总价值<=50的单词数,每个实例的输出占一行。
Sample Input
2 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 9 2 6 2 10 2 2 5 6 1 0 2 7 0 2 2 7 5 10 6 10 2 10 6 1 9
Sample Output
7 379297
题意:中文题,不过多叙述题意。
思路:这道题的话,也是套用一下母函数的模板即可。
AC代码:
#include <bits/stdc++.h>
typedef long long ll;
const int maxx=10010;
const int inf=0x3f3f3f3f;
using namespace std;
int a[maxx],b[maxx];
int sup[maxx],temp[maxx];
int main()
{
int n;
scanf("%d",&n);
while(n--)
{
for(int i=0; i<26; i++)
{
scanf("%d",&a[i]);
b[i]=i+1;
}
int last=0,last2;
memset(sup,0,sizeof(sup));
sup[0]=1;
for(int i=0; i<26; i++)
{
last2=min(last+a[i]*b[i],50);
memset(temp,0,sizeof(int)*(last2+1));
for(int j=0; j<=a[i] && j*b[i]<=last2; j++)
{
for(int k=0; k<=last && k+j*b[i]<=last2; k++)
{
temp[k+j*b[i]]+=sup[k];
}
}
memcpy(sup,temp,sizeof(int)*(last2+1));
last=last2;
}
int sum=0;
for(int i=1; i<=50; i++)
if(sup[i])
sum+=sup[i];
printf("%d\n",sum);
}
return 0;
}