Hdu 1284 coin exchange problem (DP)

Source: Internet
Author: User

[Csharp]
// Dp (full backpack)
# Include <stdio. h>
# Include <string. h>
# Define N 35000
Int dp [N];
Int main ()
{
Dp [0] = 1;
For (int I = 1; I <= 3; ++ I)
{// The backpack capacity is N, and items with a quality of I are loaded
For (int j = I; j <N; ++ j)
{
Dp [j] + = dp [j-I];
}
}
Int n;
While (scanf ("% d", & n )! = EOF)
Printf ("% d \ n", dp [n]);
Return 0;
} <Pre name = "code" class = "csharp"> // hdu 1284 lookup rule
// Give n to check the number of 2 and 3 in n.
// Read the code and watch
# Include <stdio. h>
# Include <string. h>
# Define N 35000
_ Int64 ans [N];
Int main ()
{
Int n; // Number of two I can be calculated
For (int I = 0; I <N; ++ I)
// + 1 indicates that all the values are composed of 1 (only in the case of 1)
Ans [I] = I/2 + 1;
// This line indicates the combination of 2 and 1.
// Push back from the front, it can be composed of three, for example, ans [3] indicates that the money is 3 hours
// When it is composed of 1 or 2 cent coins, it can be expressed as 0 and a 3 cent coin is added (the number of methods is
// The number of methods composed of 1, 2, and 3 when the money is 0 plus 3)
// Therefore ans [I] + = ans [I-3] + 1; do not need the + 1
For (int I = 3; I <N; ++ I) ans [I] + = ans [I-3];
// This line of ans [I] indicates the combination of 2 and 3.
// Ans [6] is equivalent to ans [6] composed of 2 and ans [6-3] composed of 1, 2 and 3.
// In this way, you can add a situation consisting of 3 points.
While (scanf ("% d", & n )! = EOF)
Printf ("% I64d \ n", ans [n]);
Return 0;
} </Pre> <br>
<Pre> </pre>
<P> </p>
<Pre> </pre>
<Br>
<P> </p>

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.