Generating function problem: HDU2082 find words

Problem Description assume x1 letters A, B letters X2, ...
X26 letter Z, while assuming the value 1 for the letter A, letter B value is 2, ...
letter Z value of 26. So, for a given letter, how much value can be found <= 50 words of it? Value is a word consisting of all of the letters of a word sum value, for example, the value of the word ACM is 3 + 1 + 14 = 18, the value of the word is HDU 21 + 8 + 4 = 33. (Consisting of a word regardless of the order, such as the ACM and the same word is considered CMA).

Input a first input integer N, the representative number of test examples. Then comprises N rows, each row comprising 26 <= x1 20 of integers, x2, ... x26.

Output For each test case, output a total value could find <= 50 the number of words, the output of each instance per line.

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

#include<stdio.h>
#include<string.h>
//#include <stdbool.h>
#include <algorithm>
#include<queue>
using  namespace std;
//HDU2082找单词 对于母函数的套用:
//先回忆一下母函数是怎么一回事:(x0+x1+x2)*(x0+x2+x4)这样子的
//然后需要知道怎么相乘 有一个数组来记录对应次方的系数c[],然后一个数组来初始化temp[].
//而对于该题来说,已经知道的是每一个位置的值,而数组值就是对应的个数,也就是增加多少次
//然后对于每组有数存在的数据 有 不选,选一个。。。等操作 ,先对第一个赋初值
int main()
{//先输入实例的例子
    int n,i,j,k;
    int c[1000];
    int temp[1000];//这两个数组分别是用来存储对应次数的系数和中间交换的
    scanf("%d",&n);
    while(n--){
        //再输入每一次实例的值
        int a[26];
        for(i=0;i<26;i++){
            scanf("%d",&a[i]);//输入单词的个数
        }
        //先对第一个次数赋初值,在给定的范围里赋1,和temp全为0
        memset(temp,0,sizeof(temp));
        memset(c,0,sizeof(c));
        for(i=0;i<=a[0];i++){//这里应该是等于的,第一项的各个次数的系数
            c[i]=1;
        }
        //然后开始前一项乘以第二项.从第二项开始
        for(i=2;i<=26;i++){
            for(j=0;j<=50;j++){//第一项的(x0到xn)
                for(k=0;k+j<=50&&k<=a[i-1]*i;k+=i){//第二项的,然后是判断条件,k是次数,k的次数是小于i*a[i]的,然后还有一个条件要和j相结合,他们次数之和要小于50
                    temp[k+j]+=c[j];//这里有个小Bug 应该是a[i-1] 因为数组是从0开始的
                }
            }
            //然后再把中间值复制到最终值中
            for(j=0;j<=50;j++){
                c[j]=temp[j];
                //这一步忘记了
                temp[j]=0;//赋初值
            }
        }
        int sum=0;
        for(i=1;i<=50;i++){
            sum+=c[i];//记录前面50个的系数,这里又是一个Bug 要从1开始,而不是0.。。
        }
        printf("%d\n",sum);

    }

}

Published 72 original articles · won praise 5 · Views 2819

Guess you like

Origin blog.csdn.net/qq_41115379/article/details/104906584