Hdu1121 complete the sequence

Source: Internet
Author: User

Http://acm.hdu.edu.cn/showproblem.php? PID = 1, 1121

Here is a series of integers that contain S integers, so that you can find the polynomial P (n) = AD. N ^ d + aD-1.n ^ D-1 +... + a1.n + a0: When the degree of the polynomial is the hour, the following C integers are output to satisfy the polynomial.

AlgorithmAnalysis: HDU recommended for DP, no idea, find the problem report (http://rchardx.is-programmer.com/posts/16142.html), said to be differential. My understanding is as follows: Find the difference between each item and the previous one, and then observe the law, for any polynomial satisfying P (n) = AD. N ^ d + aD-1.n ^ D-1 +... + a1.n + a0 of the d degree polynomial, take the first order of the difference: TMP = P (n)-(N-1) must be a D-1 degree polynomial, and so on, take the n-1 order difference, and there is only one number D (ProgramFor f [n-1] [0]), if D = 0, if you want to minimize the order of P (n), the next M number in the n-1 difference should be 0, if D! = 0, when the next M number is d, then the first order of the n-2 is a polynomial of the First Order (only the first degree of Polynomial (a1.n + a0, tolerances for A1) the difference is a constant), The n-1 order is 0 order polynomial, in order to ensure the minimum order d

 

Code

  # Include <  Stdio. h  >  
# Define Nn 102
Int Main ()
{
Int T, I, J, S, C;
Int F [NN] [NN];
Scanf ( " % D " , & T );
While (T -- ){
Scanf ( " % D " , & S, & C );
For (I = 0 ; I < S; I ++ )
Scanf ( " % D " , & F [ 0 ] [I]);
For (I = 1 ; I < S; I ++ )
For (J = 0 ; I + J < S; j ++ )
F [I] [J] = F [I - 1 ] [J + 1 ] - F [I - 1 ] [J];
For (I = 1 ; I <= C; I ++ )
F [s - 1 ] [I] = F [s - 1 ] [ 0 ];
For (I = S - 2 ; I > = 0 ; I -- )
For (J = S - I; j < C + S; j ++ )
F [I] [J] = F [I] [J - 1 ] + F [I + 1 ] [J - 1 ];
For (I = S; I < S + C - 1 ; I ++ )
Printf ( " % D " , F [ 0 ] [I]);
Printf ( " % D \ n " , F [ 0 ] [I]);
}
Return 0 ;
}

 

 

 

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.