砝码称重
来源:NOIP1996(提高组)
【问题描述】
【输入文件】
【输出文件】
【输入样例】
【输出样例】
=======================
数据:
输入 | 输出 |
1 1 0 0 0 0 | Total=3 |
2 2 0 0 0 0 | Total=6 |
1 0 3 0 0 0 | Total=7 |
3 4 0 5 0 0 | Total=36 |
2 2 2 2 2 2 | Total=82 |
0 3 2 7 4 5 | Total=185 |
0 6 3 4 2 1 | Total=79 |
1 2 3 4 5 6 | Total=204 |
6 5 4 3 2 1 | Total=83 |
10 10 10 10 1 1 | Total=140 |
========================
{
ID:jie19952
PROG:
LANG:PASCAL
}
type
re=record
sum:longint;
weight:longint;
end;
var
a:array[1..6]of re;
f_bool:array[0..1000]of boolean;
ans:longint;
procedure init;
begin
assign(input,'fama.in');
assign(output,'fama.out');
reset(input); rewrite(output);
end;
procedure terminate;
begin
close(input); close(output);
halt;
end;
procedure main;
var
t,i,j,k:longint;
begin
a[1].weight:=1; a[4].weight:=5;
a[2].weight:=2; a[5].weight:=10;
a[3].weight:=3; a[6].weight:=20;
for t:=1 to 10 do
begin
for i:=1 to 6 do
read(a[i].sum);
//fillchar(f,sizeof(f),0);
fillchar(f_bool,sizeof(f_bool),false);
f_bool[0]:=true;
for i:=1 to 6 do
for j:=1000 downto 0 do
if f_bool[j] then
for k:=1 to a[i].sum do
begin
f_bool[j+a[i].weight*k]:=true;
end;
ans:=-1;
for i:=0 to 1000 do
if f_bool[i] then inc(ans);
writeln('TOTAL=',ans);
end;
end;
begin
init;
main;
terminate;
end.