[Backpack] poj 1882

Source: Internet
Author: User

The question is a bit wordy. To put it bluntly, a maximum of S and N sets of stamps are provided. Each set has m stamps with a face value of AI, the maximum continuous nominal value and (starting from 1) can be formed when the limit is not exceeded ).

DP [N]: Minimum number of stamps that constitute I + full backpack, updating several record values

# Define n 1100int DP [N]; // minimum number of elements whose nominal value is I: int A [12] [12]; int main () {int S; while (scanf ("% d", & S) {int I, j, k; int N; scanf ("% d", & N ); int ans = min; int Index = 0; int num = max; int big = 0; for (I = 1; I <= N; I ++) {scanf ("% d", & A [I] [0]); int M = A [I] [0]; for (j = 1; j <= m; j ++) {scanf ("% d", & A [I] [J]);} DP [0] = 0; int maxv = A [I] [m] * s; For (j = 1; j <= maxv; j ++) DP [J] = (1 <30 ); for (j = 1; j <= m; j ++) {for (k = A [I] [J]; k <= maxv; k ++) {DP [k] = min (DP [K], DP [k-A [I] [J] + 1) ;}} for (j = 1; j <= maxv; j ++) {If (DP [J]> S) break;} j --; If (j> ans) {ans = J; Index = I; num = m; big = A [I] [m];} else if (j = ans) {If (M <num) {ans = J; Index = I; num = m; big = A [I] [m];} else if (M = num) {if (a [I] [m] <big) {ans = J; Index = I; num = m; big = A [I] [m] ;}}} printf ("Max coverage = % d :", ans); for (I = 1; I <= num; I ++) {printf ("% d", a [Index] [I]);} puts ("");} 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.