Pku1252 euro Efficiency

Source: Internet
Author: User

There are 6 currencies with a nominal value. The smallest value is 1, and the minimum number of currencies is calculated as 1 .. 100. The maximum value and their average value are output. Subtraction can be used.

For example, 6 = 1 + 2 + 3, 6 = 7-1, then the minimum number of currencies for 6 is 2.

It is a backpack with no lower limit. You can open the volume array to 3000 + (after testing ).

View code

 1 program pku1252(input,output);
2 var
3 f : array[-3000..3000] of longint;
4 v : array[1..6] of longint;
5 cases,e : longint;
6 procedure init;
7 var
8 i : longint;
9 begin
10 for i:=1 to 6 do
11 read(v[i]);
12 readln;
13 fillchar(f,sizeof(f),63);
14 f[0]:=0;
15 end; { init }
16 function min(aa,bb : longint ):longint;
17 begin
18 if aa>bb then
19 exit(bb);
20 exit(aa);
21 end; { min }
22 procedure main;
23 var
24 i,j : longint;
25 begin
26 for i:=1 to 6 do
27 begin
28 for j:=v[i]-3000 to 3000 do
29 f[j]:=min(f[j],f[j-v[i]]+1);
30 for j:=3000-v[i] downto -3000 do
31 f[j]:=min(f[j],f[j+v[i]]+1);
32 end;
33 end; { main }
34 procedure print;
35 var
36 i,max,sum : longint;
37 begin
38 sum:=0;
39 max:=0;
40 for i:=1 to 100 do
41 begin
42 inc(sum,f[i]);
43 if f[i]>max then
44 max:=f[i];
45 end;
46 writeln((sum/100):0:2,' ',max);
47 end; { print }
48 begin
49 readln(cases);
50 for e:=1 to cases do
51 begin
52 init;
53 main;
54 print;
55 end;
56 end.

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.