Mr Zz

导航

HDU 找单词

就是给你26个字母 A代表1 。。。。Z代表26  输入每个字母的个数 求少于50总和的单词数目

注意 单词字母不分顺序

母函数就可以解决啦  母函数算出来 系数刚好是所有可能的方案数 所以只要把前面 50 个加起来就行了

#include<iostream>
#include<cstring>
#include<stdio.h>
#include<stdlib.h>
using namespace std;
int len[27];
int c1[51];
int c2[51];
int main(){
int n;
freopen("t.txt","r",stdin);
while(scanf("%d",&n)!=EOF) {
for(int i=0;i<n;i++) {
memset(c1,0,sizeof(c1));
memset(c2,0,sizeof(c2));
c1[0] = 1;
for(int j=1;j<=26;j++) {
scanf("%d",&len[j]);
}
for(int x=1;x<27;x++) {
for(int y=0;y<=50;y++) {
for(int z=0;z<=x*len[x]&&y+z<=50;z+=x) {
c2[y+z] += c1[y];
}
}
for(int z=0;z<=50;z++) {
c1[z] = c2[z];
c2[z] = 0;
}
}
int sum = 0;
for(int x=1;x<=50;x++)
sum += c1[x];
printf("%d\n",sum);
}
}
return 0;
}

posted on 2011-10-18 20:26  Mr Zz  阅读(186)  评论(0)    收藏  举报