Blue Bridge Cup Java algorithm to improve the design of stamp value

Source: Internet
Author: User

Problem description Given an envelope, a maximum of only N stamps can be pasted, calculated in the case of a given K (n+k≤13) stamp (assuming that all stamps are sufficient), how to design the face value of the stamp, the maximum value max, so that each postage value between the 1~max can be obtained.

For example, n=3,k=2, if the face value is 1 points, 4 points, then the 1 cent between the points of each postage value can be obtained (of course, 8, 9 and 12 points), if the face value of 1 points, 3 points, the 1 points between the value of each postage can be obtained. It can be verified that when n=3,k=2, 7 points is the maximum number of consecutive postage that can be obtained, so max=7, the face value is 1 points, 3 points respectively. Input format line, two number n, k output format two lines, the first row of the output design of the stamp value in ascending order, the second line output "max=xx" (without quotation marks), where xx is the maximum number of consecutive postage to be obtained. Sample Input 3 2 sample Output 1 3
Max=7
Import Java.util.scanner;public class Main {static int N, k;static int count[] = new Int[11];static int sum[] = new int[11 ];static int value[] = new int[1000];p ublic static void Main (string[] args) {Scanner in = new Scanner (system.in); N = In.nextint (); K = In.nextint (); In.close (); count[1] = 1; Dp (1); for (int i = 1; I <= K; i++) {System.out.print (Sum[i] + "");} System.out.println (); System.out.print ("max=" + (Sum[0]-1));} private static void DP (int dp) {int x = Getbig (DP); if (DP = = K) {return;} for (int i = x; i > COUNT[DP]; i--) {COUNT[DP + 1] = I;DP (DP + 1);}} private static int getbig (int dp) {for (int i = 1; i <=; i++) {Value[i] = 1000;for (int j = 1; J <= DP; j + +) if (i >= count[j]) {Value[i] = Math.min (Value[i], Value[i-count[j]] + 1);} if (Value[i] > N) {if (i > Sum[0]) {sum[0] = i;for (int j = 1; j <= dp; ++j) SUM[J] = Count[j];} return i;}} return 0;}}

  

Blue Bridge Cup Java algorithm improves stamp face value design

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.