HDU 2082 找单词 (母函数模板)

来源:互联网 发布:linux 查看时区 编辑:程序博客网 时间:2024/06/06 00:34

找单词

Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 8070    Accepted Submission(s): 5652


Problem Description
假设有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
21 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 09 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
7379297
 

Source
2006/1/15 ACM程序设计期末考试
 

Recommend
lcy   |   We have carefully selected several similar problems for you:  2079 1085 1171 1398 2152 

#include <iostream>#include<cstdio>#include<cstring>using namespace std;const int maxn=60;int a[maxn],b[maxn];int main(){    int T,num;    cin>>T;    while(T--)    {        memset(a,0,sizeof(a));        memset(b,0,sizeof(b));        a[0]=1;        for(int i=1;i<=26;i++)        {            scanf("%d",&num);            if(num==0)continue;            for(int j=0;j<=50;j++)            {                for(int k=0;k<=num&&k*i+j<=50;k++)                {                    b[k*i+j]+=a[j];                }            }            for(int j=0;j<=50;j++)            {                a[j]=b[j];                b[j]=0;            }        }        int total=0;        for(int i=1;i<=50;i++)            total+=a[i];        printf("%d\n",total);    }    return 0;}


阅读全文
0 0