Path to acm-path to acm by XiaoYu

Source: Internet
Author: User

Path to acm-path to acm by XiaoYu

The mother function is also called a generative function. It was originally a mathematical term and is an important theory in composite mathematics.

The generative function is to construct such a polynomial function g (x), so that the n coefficient of x is f (n ).

For the primary function, we can see the following two sentences at most:

1. "The addition law of the combination problem corresponds to the power of the Power Series ."
2. "Apply a pair of discrete series and idempotent series, and associate the relationship between discrete series to the operational relationship between them. Finally, the structure of the discrete series is determined in the form of idempotent series. "
The primary function can solve some problems, such as the weight problem, integer division, and so on.


Weight problems:
There is one weight for one gram, two grams, three grams, and four grams. What kind of weight can I claim? What are the solutions for each weight?

The following is a solution to this problem using the primary function:

First, we use X to represent the weight, and X to represent the weight. Then, if the function is used to represent the weight that each weight can be called,

One 1 gram weight can be represented by the Function X ^ 0 + X ^ 1,

1 2 grams of weight can be represented by the Function X ^ 0 + X ^ 2,

And so on.

If we multiply the two polynomials above, we can get X ^ 0 + X ^ 1 + X ^ 2 + X ^ 3. Multiply it with X ^ 0 + X ^ 3, obtain X ^ 0 + X ^ 1 + X ^ 2 + 2 * X ^ 3 + X ^ 4 + X ^ 5 + X ^ 6.

Then multiply it with X ^ 0 + X ^ 4, finally, we get X ^ 0 + X ^ 1 + X ^ 2 + 2 * X ^ 3 + 2 * X ^ 4 + 2 * X ^ 5 + 2 * X ^ 6 + 2 * X ^ 7 + X ^ 8 + X ^ 9 + X ^ 10.

Because X's exponent represents the weight, in the phase multiplication, according to the power algorithm (same base power multiplication, exponent addition), the result is exactly all the solutions. Furthermore, the coefficient before each X represents several solutions.

Note that if there are two 1-gram weights, X ^ 0 + X ^ 1 + X ^ 2 should be used instead of X ^ 0 + 2 * X ^ 1.



Integer Division is a classic problem. The division rules are not described in detail. Compared with the above problem, the number of each weight is no longer one, but unlimited. So,

A 1-gram weight can be X ^ 0 + X ^ 1 + X ^ 2 + X ^ 3 ...... Indicates,

2 grams of weight can be X ^ 0 + X ^ 2 + X ^ 4 + X ^ 6 ...... Indicates,

3 grams of weight can be X ^ 0 + X ^ 3 + X ^ 6 + X ^ 9 ...... Indicates,

And so on.

Returns the coefficient of X ^ n after multiplication.

In the future, ACM will inevitably encounter such a problem. We only need to simulate the multiplication of two polynomials.


The idea is to open two arrays. One array is ans [], which is used to save the coefficients of the current polynomial. temp [] is a temporary array, it is used to save the temporary results of each computation. After calculation, it is assigned to ans [] And then cleared for the next computation;

During computation, we open a three-layer for loop, the outermost layer, and record that it is multiplying the number of polynomials. The second layer indicates each item in c1, and the third layer indicates each item in the polynomial.

Exercise questions: HDU 1085 HDU1398 HDU1028 HDU1171

Http://blog.csdn.net/jk13171217/article/details/38303725 hdu 1028

Http://blog.csdn.net/jk13171217/article/details/38303995 hdu 1085

Http://blog.csdn.net/jk13171217/article/details/38303933 hdu 1398

Hdu 1171 http://blog.csdn.net/jk13171217/article/details/38303111 (detail 1171)



How does ACM master function algorithm work? Please.

Recommended questions: acm.pku.edu.cn/JudgeOnline/problem? Id = 1141 simple acm.pku.edu.cn/JudgeOnline/problem? Id = 2288 moderate, classic TSP Problem acm.pku.edu.cn/JudgeOnline/problem? Id = 2411 moderate, status compression DP acm.pku.edu.cn/JudgeOnline/problem? Id = 1112 medium acm.pku.edu.cn/JudgeOnline/problem? Id = 1848 medium, tree-like DP. Acm.zju.edu.cn/show_problem.php? Pid = 1234 medium, exercise acm.pku.edu.cn/JudgeOnline/problem in the competition for algorithm art and Informatics? Id = 1947 medium, exercise acm.pku.edu.cn/JudgeOnline/problem in the competition for algorithm art and Informatics? Id = 1946 medium, exercise in the competition for algorithm art and informatics... the remaining full text>

A very simple acm primary function question. I hope Daniel can answer it for me!

# Include <iostream>
Using namespace std;
Const int lmax= 300;
Int c1 [lmax + 1], c2 [lmax + 1];
Int main (void)
{
Int n, I, j, k;

While (cin> n & n! = 0)
{
For (I = 0; I <= n; I ++)

{
C1 [I] = 1; c2 [I] = 0;
}

For (I = 2; I <= 17; I ++)
{
For (j = 0; j <= n; j ++)
{
For (k = 0; k + j <= n; k + = I * I)
{

C2 [j + k] + = c1 [j];
In this case, c2 [j + k] is equal to c1 [j + k];
Therefore, we need to assign all the c2 arrays to the c1 array later, because c2 is only a temporary storage and will be cleared later.
}
}
For (j = 0; j <= n; j ++)
{
C1 [j] = c2 [j]; // assign the latest value to the c1 array,

C2 [j] = 0; // clear c2. Because I needs to add 1, c2 is to be cleared. c2 stores the increment when I is equal to a fixed value.
}
}
// This Is What I added
For (j = 0; j <= n; j ++)
{
Cout <c1 [j] <endl;
}
// Cout <c1 [n] <endl;

}
Return 0;
}
From the output, we can see that c1 [1] is saved. When the input is 1, the number of outputs is 1, that is, input 1, output c1 [1], and so on.
This algorithm is redundant. For example, if you input 50, the output from 1 to 50 will be saved in c1 [lmax + 1, in addition, the first for loop does not need to be written as I <= 27; because if the input is 30, the I can only be up to 5 (the 5 square is 25, and the 6 square 32 is greater than 30, in fact, I think it's hard to say. I don't know if you understand it. As long as you follow the cycle step by step and list the values of c1 and c2, you should be able to understand it.




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.