HDU2082 the template problem of parent function

Source: Internet
Author: User

Find the wordsTime limit:1000/1000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): 5782 Accepted Submission (s): 4062


Problem description assumes X1 letter A, X2 letter B,..... x26 Letter Z, assuming the value of the letter A is 1 and the value of the letter B is 2,..... The value of the letter Z is 26. So, for a given letter, how much value can you find in <=50 words? The value of a word is the sum of the values of all the letters that make up a word, for example, the value of the word ACM is 1+3+14=18, and the value of the word hdu is 8+4+21=33. (The composed word is not related to the order, such as ACM and CMA think of the same word).

Input inputs are first an integer n, which represents the number of test instances.
It then includes n rows of data, each of which consists of 26 <=20 integer x1,x2,..... x26.

Output for each test instance, outputs the number of words that can be found for the total value of <=50, with one row for each instance output.
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 Program Design Final Exam


Knowledge Points:

Parent function (Generate function):

    generation function has generic build function and exponential type generation function two (the subject is the normal type).

    form, the common type female function is used to solve the combination problem,

The exponential female function is used to solve the permutation problem of multiple sets.

The parent function can also solve the general problem of recursive series (for example, using the parent function to solve the Fibonacci sequence, Catalan number of the general formula).

Common parent functions:

construct the parent function g (x), g (x) = a0 + a1*x + a2*+ a3*+....+ an*, the G (x) is the parent function of the sequence a0,a1...an.

Usually the common parent function is used to solve the combinatorial problem of multiple sets , the idea is to construct a function to resolve the problem, the general process is as follows:

1. Build the Model: item n, each quantity is K1,k2,.. KN, each item has a property value P1,p2,... pn, (such as the letter value of the subject),

The value of the property and the number of item combinations for M. (If the number of Ki Infinity is established, that corresponds to the index of the KI term in the following equation to infinity)

    2. Construct the parent function: G (x) = (1++ ...) (1+++ ...) ... (1+++ ...)         (a)

                                 =a0 + a1*x + a2*  + a3* +....+ akk*     (set kk=k1 p1+k2 p2+...kn pn)   (b)

                   G (x) Meaning: AK is the attribute value and are the combined methods of K.

The idea of using the parent function:

1. The addition rule of the combinatorial problem corresponds to the power of the power series.

2. The discrete series and the power series corresponding to the discrete sequence of the relationship between the interaction between the power series, and finally by the form of power series

Determine the construction of discrete series.

Code implementation:

The g (x) is a multiplicative one. Shilling g=1= (1+0*x+0*+ ... 0*), then g=g* (1++ ...) Get the formula of form (b) ... Finally make g=g* (1+++ ...).

Exercises

1. Modeling: Items (Letters) 26 kinds, each quantity x1,x2...x26, the attribute value is 1,2,3..26, the attribute value and the <=50 combination method number.

2.G (x) = (1++ ...) (1+++ ...) ... (1++ ...)

#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <string.h>


using namespace Std;
int c1[100],c2[100];
int a[30];
int main ()
{
int t;
CIN >> T;
while (T--)
{
for (int i = 1; I <=; i + +)
CIN >> A[i];
Memset (C1,0,sizeof (C1));
memset (c2,0,sizeof (C2));
C1[0] = 1;///initialization
for (int i = 1; I <=; i + +)//26 polynomial
{
for (int j = 0; J <=; J + +)///The corresponding exponent in each polynomial
for (int k = 0; k <= a[i] && k * i + j <=, K + +)///k*i denotes exponential of multiplicative polynomial
C2[j + k * I] + = c1[j];
memcpy (c1,c2,sizeof (C2));///c2 array values are assigned to C1
memset (c2,0,sizeof (C2));///C2 initialization
}
Accumulation
int sum = 0;
for (int i = 1; I <=; i + +)
Sum + = C1[i];
cout << sum << endl;
}
return 0;
}


HDU2082 the template problem of parent function

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.