A problem of solving a mother function

Source: Internet
Author: User

Because oneself is the first time to do the problem of the mother function, feel very difficult, the following words are addressed to the novice

The title is this: http://acm.hdu.edu.cn/showproblem.php?pid=1028

After reading the topic, it probably means this: give an integer n, let you ask for the split of N.

For example:

Assume N is 4, we can find:
4 = 4;
4 = 3 + 1;
4 = 2 + 2;
4 = 2 + 1 + 1;
4 = 1 + 1 + 1 + 1;

There are 5 types of split methods found.

So how is programming implemented?

Look at the code, as follows:

Female function//g (x) = (1 + x^1 + x^2..+x^n) (1 + x^2 + x^4 + x^6 + ...) (1 + x^3 + x^6 + ...) (..) (1 + x^n)//The exponent of x in the first expression (1 + x^1 + x^2..+x^n) represents "the number of occurrences of ' 1 ' in the solution" such as X^2 = x^ (1 * 2) which is ' 1 ' appears two times x^3 = x^ (1 * 3) ' 1 ' appears second expression 3 times//Similar Formula (1 + x^2 + x^4 + x^6 + ...) x^4 = x^ (2 * 2) ' 2 ' appears two times x^6 = x^ (2 * 3) ' 1 ' appears 3 times//... And so on, "* 1 (0) is an application that represents the number of occurrences of 0"//multiplication: Each expression represents all the values of a variable "for example, the first expression means ' 1 ' can be taken (that is, the number of occurrences of ' 1 ' after n split) can be {0,1,2...N}"//  The product of all the values of each variable is the solution of the problem (shown in this question as ' and ')//Example: 4 = 2 + 1 + 1 is x^ (1 * 2) "' 1 ' appears 2 times"//* x^ (2 * 1) "' 2 ' appears 1 Times"//* x^ (3 * 0) "' 3 ' appears 0 times"//* x^ (4 * 0) ". "//result//The above 4 fractions multiplied by equals 1 * (X^4) represents a split decomposition of 4//So G (x) expands after the coefficient of X^n is n the number of splits # include <stdio.h>int main () {int c1[123], C2 [123], N;while (scanf ("%d", &n)! = EOF) {for (int i = 0; I <= n; i++)//Initialize first expression the coefficients of all index entries are now 1{c1[i] = 1; C2[i] = 0;} for (int i = 2; I <= n; i++)//2nd to nth expression {for (int j = 0; J <= N; j + +)//c1 is the coefficient for each exponent entry after the first i-1 expression multiplicative {for (int k = 0; j + K < = N; K + = i)//k for the first expression of the exponent of each item is 1 "i.e. x^ (i * 0)" (exponent k=0), the second is x^ (i * 1) (exponent is k=i), the third is x^ (i * 2) ... So the step of KLength for I{c2[j + K] + = c1[j];//(ax^j) * (x^k) = ax^ (j+k)-c2[j+k] + = a "the coefficients of each term for each of the expressions are 1; A is the value of c1[j] (the coefficient of x^j); C2 is the exponent after the first expression The coefficients "}}for (int j = 0; J <= N; j + +)//refresh the coefficients of each index term for the current multiplicative result {C1[j] = c2[j]; C2[J] = 0;}} printf ("%d\n", C1[n]);} return 0;}

  

A problem of solving a mother function

Related Article

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.