l:=a[i,i]; a[i,i]:=a[i,t]; a[i,t]:=l;
end;
for i:=1 to 3 do
begin
for j:=1 to 3 do write(a[i,j],' ');
writeln;
end;
readln;
end.
program P_4;
const MAX_BUFFER_SIZE = 10000;
var a,b,n:integer;
buffer:array[0..MAX_BUFFER_SIZE] of integer;
buffer_size:integer;
procedure check(pa,pb:integer);
var i:integer;
begin
for i:=0 to buffer_size do
if (buffer[i]=pa) or (buffer[i]=pb) then
begin
writeln(pa:5,pb:6);
writeln(-1);
halt;
end;
if (buffer_size < MAX_BUFFER_SIZE) then
begin
inc(buffer_size);
buffer[buffer_size]:=pa;
end;
end;
begin
read(a,b);
buffer_size:=0;
buffer[0]:=a;
n:=0;
while (a<>0) and (b<>0) do
begin
if (a>b) then
begin a:=a-b; b:=b+b; end
else
begin b:=b-a; a:=a+a; end;
inc(n);
check(a,b);
writeln(a:5,b:6);
end;
writeln(n);
end.
program P_3;
const MAX_COUNT = 1000;
var n,i,s,best_length:longint;
a:array[1..MAX_COUNT] of integer;
curr,best:array[1..MAX_COUNT,1..2] of integer;
used:array[1..MAX_COUNT] of boolean;
procedure save(p:integer);
var i:integer;
begin
best_length := p;
for i:=1 to best_length do
best[i] := curr[i];
end;
procedure put(p,s:integer);
var i,j:integer;
begin
if (p>best_length) then exit;
if (s=0) then
begin
save(p-1);
exit;
end;
for i:=n downto 1 do
if (not used[i]) then
begin
used[i] := true;
curr[p][1] := i;
for j:=(s div a[i]) downto 1 do
begin
curr[p][2] := j;
put( p+1, s - j * a[i] );
end;
used[i] := false;
end;
end;
begin
read(n);
for i:=1 to n do
begin
read(a[i]);
used[i] := false;
end;
read(s);
best_length := n+1;
put(1,s);
if (best_length < n+1) then
begin
writeln(best_length);
for i:=1 to best_length do
begin
if (i>1) then write(' + ');
write(best[i][2],'*',a[best[i][1]]);
end;
writeln;
end
else
writeln(-1);
end.
Kompyuter grafikasidan tast savollarining javoblari