P1021 stamp nominal value design, p1021 stamp nominal value

Source: Internet
Author: User

P1021 stamp nominal value design, p1021 stamp nominal value
Description

Given an envelope, up to N stamps can be pasted, and the number of stamps is calculated (assuming that the number of stamps is sufficient) for a given K (N + K ≤ 15 ), how to Design the face value of a stamp to obtain the maximum value MAX, so that ~ Each postage value between MAX can be obtained.

For example, N = 3, K = 2. If the nominal values are 1 and 4 ~ Each postage value between 6 points can be obtained (of course there are 8 points, 9 points and 12 points); If the face value is 1 point, 3 points, then 1 point ~ Each postage value between 7 points can be obtained. It can be verified that when N = 3, K = 2, 7 is the continuous maximum value of postage, so MAX = 7, the nominal value is 1 minute, 3 points.

Input/Output Format Input Format:

Two integers, N and K.

Output Format:

2 rows. A number in the first row indicates the selected nominal value, which is sorted in ascending order.

In the second row, "MAX = S" is output, and "S" indicates the maximum nominal value.

Input and Output sample Input example #1:
3 2
Output sample #1:
1 3MAX = 7

I wrote a dp and wrote a deep search result, which is as slow as the tortoise ..
However, thanks to the data,
Idea: perform in-depth search and enumeration, and calculate the value of backpack DP
1 # include <iostream> 2 # include <cstdio> 3 # include <cstring> 4 # include <cmath> 5 using namespace std; 6 const int MAXN = 1001; 7 void read (int & n) 8 {9 char c = '+'; int x = 0; int flag = 0; 10 while (c <'0' | c> '9') 11 {if (c = '-') flag = 1; c = getchar ();} 12 while (c> = '0' & c <= '9') 13 {x = x * 10 + (c-48); c = getchar ();} 14 flag = 1? N =-x: n = x; 15} 16 int n, k; 17 bool vis [MAXN]; 18 int ans [MAXN]; // 19 int dp [MAXN] selected each time; // records whether each number has a solution that can reach 20 int maxnum; 21 int out [MAXN]; 22 int ed = 0; 23 inline int pd () 24 {25 memset (dp, 0x3f, sizeof (dp); 26 dp [0] = 0; 27 int OK = 0; 28 int tot = 0; 29 for (int I = 1; I <= k; I ++) 30 tot = max (ans [I] * n, tot); 31 for (int I = 1; I <= k; I ++) // each item 32 for (int j = ans [I]; j <= n * ans [I]; j ++) 33 if (dp [j-ans [I] + 1 <= n) 34 dp [j] = min (dp [j], dp [j-ans [I] + 1); 35 for (int I = 1; I <= 170; I ++) 36 {37 if (dp [I] <888) 38 {39 OK ++; 40 continue; 41} 42 else break; 43} 44 return OK; 45} 46 inline void dfs (int now, int num) // The number of now selected, the last number of num 47 {48 ans [now] = num; 49 if (now = k) 50 {51 int hh = pd (); 52 // cout 

 

 

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.