HDU2082 母函数

简介:

                                    找单词

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


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
 
 
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

Source

Recommend
lcy

题解:普通母函数 乘完求x五十次幂前的系数和就行 


#include <iostream>
#include<cstdio>
#include<cstring>
using namespace std;

int main()
{
    int t,a[60],b[60],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 ans=0;
        for(int i=1; i<=50; i++)
            ans+=a[i];
        printf("%d\n",ans);
    }
    return 0;
}


目录
相关文章
|
16天前
|
机器学习/深度学习
N皇后问题(HDU—2253)
N皇后问题(HDU—2253)
HDU7018.Banzhuan(计算几何+贪心)
HDU7018.Banzhuan(计算几何+贪心)
81 0
HDU7018.Banzhuan(计算几何+贪心)
HDU-1370,Biorhythms(中国剩余定理)
本题主要就是应用中国剩余定理。
|
并行计算 算法 Java
HDU 1874 畅通工程续【Floyd算法实现】
畅通工程续 Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 53806    Accepted Submission(s): 20092 Problem Description 某省自从实行了很多年的畅通工程计划后,终于修建了很多路。
1066 0
poj-2909-哥德巴赫猜想
Description For any even number n greater than or equal to 4, there exists at least one pair of prime numbers p1 and p2 such that n = p1 + p2 This conjecture has not been proved nor refused yet.
774 0
【HDU 4451 Dressing】水题,组合数
有衣服、裤子、鞋数量分别为n,m,k,给出p对不和谐的衣-裤或裤-鞋搭配,问一共有多少种和谐的衣裤鞋的搭配。 全部的组合有Cn1Cm1Ck1种。 设p对中有p1对衣-裤,p2对裤-鞋,则不和谐的搭配共有p1*Ck1+p2*Cn1种,但有被重复计算两次的搭配共p3对,它们引用了同一裤。
884 0
数论 + 公式 - HDU 4335 What is N?
What is N?  Problem's Link:  http://acm.hdu.edu.cn/showproblem.php?pid=4335   Mean:  给你三个数b、P、M,让你求有多少个n满足下式。
835 0
|
容器
hdu3388 Coprime【容斥原理】
Problem Description Please write a program to calculate the k-th positive integer that is coprime with m and n simultaneously.
1110 0
|
机器学习/深度学习 算法
数论 - 欧拉函数模板题 --- poj 2407 : Relatives
Relatives Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 11372   Accepted: 5544 Description Given n, a positive in...
979 0