HDU 1085 holding bin-Laden captive! (DP)

Source: Internet
Author: User

Question link: http://acm.hdu.edu.cn/showproblem.php? PID = 1, 1085

Solution Report: There are three kinds of coins with nominal values: 1, 2, and 5. The numbers of these three coins are num_1, num_2, and num_5. Ask what is the minimum value of the money you cannot gather.

DP, open an array like DP [I] [3], then DP [I] [0] indicates that DP [I] [0] is required for making I RMB, and DP [I] [1] is required, DP [I] [2] Five blocks, and then follow the recurrence, there are three ways to obtain I, the first is the I-1 plus a piece, the second is the I-2 plus one piece of two, the fourth is the I-5 plus a five, and then each time you judge whether there is more than a number on the line, if we find that none of the three methods can be I, it means that the smallest value that cannot be I.

1 # include <cstdio> 2 3 struct node 4 {5 int A, B, C; 6} DP [8005]; 7 int main () 8 {9 int N1, N2, n5; 10 while (scanf ("% d", & N1, & N2, & N5), N1 + N2 + N5) 11 {12 DP [0]. a = 0; 13 DP [0]. B = 0; 14 DP [0]. C = 0; 15 int ans = 0; 16 for (INT I = 1; I <= N1 + 2 * N2 + 5 * N5 + 1; ++ I) // The addition of 1 is in all can be achieved in the case of direct results than the total number of 1 17 {18 if (I> = 1 & DP [I-1]. A + 1 <= N1) 19 DP [I] = DP [I-1], DP [I]. A + = 1; 20 else if (I> = 2 & DP [I-2]. B + 1 <= N2) 21 DP [I] = DP [I-2], DP [I]. B + = 1; 22 else if (I> = 5 & DP [I-5]. c + 1 <= N5) 23 DP [I] = DP [I-5], DP [I]. c + = 1; 24 else25 {26 ans = I; 27 break; 28} 29} 30 printf ("% d \ n", ANS); 31} 32 return 0; 33} 34 35
View code

 

HDU 1085 holding bin-Laden captive! (DP)

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.