zoukankan      html  css  js  c++  java
  • HDU 2082 找单词(生成函数)

    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   |   We have carefully selected several similar problems for you:  2079 1085 1171 1398 2152 
     
     
    生成函数
    比较水。。
    对于每个单词构造一个多项式
    第$i$个单词为$A(i) = x^i +x^{2i} +dots$
    然后全都乘起来就是答案
    记得清数组
    感觉这题强上背包也可以做。。
     
    #include<cstdio>
    #include<algorithm>
    #include<cstring>
    //#include<iostream>
    using namespace std;
    const int MAXN = 51;
    inline int read() {
        char c = getchar(); int x = 0, f = 1;
        while(c < '0' || c > '9') {if(c == '-') f = -1; c = getchar();}
        while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
        return x * f;
    }
    int num[MAXN], cur[MAXN], nxt[MAXN];
    int main() {
        //freopen("a.in", "r", stdin);
        int QwQ = read();
        while(QwQ--) {
            memset(cur, 0, sizeof(cur));
            for(int i = 1; i <= 26; i++) num[i] = read();
            for(int i = 0; i <= num[1]; i++) cur[i] = 1;
            for(int i = 2; i <= 26; i++) {
                for(int j = 0; j <= 50; j++) 
                    for(int k = 0; j + k * i <= 50 && k <= num[i]; k++) //当前价值 
                        nxt[j + k * i] += cur[j]; 
                memcpy(cur, nxt, sizeof(nxt));
                memset(nxt, 0, sizeof(nxt));
            }
            int ans = 0;
            for(int i = 1; i <= 50; i++) ans += cur[i];
            printf("%d
    ", ans);
        }
        return 0;
    }
  • 相关阅读:
    左右下划线,中间文字
    sql语言动词
    SQL语言的四个组成部分
    MySQL执行一条查询语句的内部执行过程
    07 | 行锁功过:怎么减少行锁对性能的影响?
    06 | 全局锁和表锁 :给表加个字段怎么有这么多阻碍?
    05 | 深入浅出索引(下)
    04 | 深入浅出索引(上)
    03 | 事务隔离:为什么你改了我还看不见?
    02 | 日志系统:一条SQL更新语句是如何执行的?
  • 原文地址:https://www.cnblogs.com/zwfymqz/p/9152465.html
Copyright © 2011-2022 走看看