bài kt 1 tiết 1
2 posters
Trang 1 trong tổng số 1 trang
bài kt 1 tiết 1
program hocsinh;
const max=20;
fi='b1kt1t.inp';
fo='b1kt1t.out';
type vector = array[0..max] of longint;
var x, a: vector;
n, s:longint;
f: text;
{ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ}
procedure nhap;
var i: integer;
begin
assign(f,fi);
reset(f);
readln(f,n,s);
for i := 1 to n do
read(f,a[i]);
close(f);
end;
{ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ}
procedure ghinghiem(x:vector);
var i:longint;
begin
for i:=1 to n do
if(x[i]=1)then
write(f,a[i],' ');
writeln(f);
end;
{ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ}
function kiemtra(x: vector):boolean;
var i, tong:longint;
begin
tong := 0;
for i:= 1 to n do
if(x[i]=1)then
tong := tong + a[i];
if(tong=s)then
exit(true)
else
exit(false);
end;
{ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ}
procedure tim(i:longint);
var j:longint;
begin
for j := 0 to 1 do
begin
x[i]:=j;
if ((i=n)and(kiemtra(x))) then
ghinghiem(x)
else
if(i<n)then
tim(i+1);
end;
end;
{ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ}
BEGIN
nhap;
x[0]:=0;
assign(f,fo);
rewrite(f);
tim(1);
close(f)
END.
const max=20;
fi='b1kt1t.inp';
fo='b1kt1t.out';
type vector = array[0..max] of longint;
var x, a: vector;
n, s:longint;
f: text;
{ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ}
procedure nhap;
var i: integer;
begin
assign(f,fi);
reset(f);
readln(f,n,s);
for i := 1 to n do
read(f,a[i]);
close(f);
end;
{ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ}
procedure ghinghiem(x:vector);
var i:longint;
begin
for i:=1 to n do
if(x[i]=1)then
write(f,a[i],' ');
writeln(f);
end;
{ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ}
function kiemtra(x: vector):boolean;
var i, tong:longint;
begin
tong := 0;
for i:= 1 to n do
if(x[i]=1)then
tong := tong + a[i];
if(tong=s)then
exit(true)
else
exit(false);
end;
{ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ}
procedure tim(i:longint);
var j:longint;
begin
for j := 0 to 1 do
begin
x[i]:=j;
if ((i=n)and(kiemtra(x))) then
ghinghiem(x)
else
if(i<n)then
tim(i+1);
end;
end;
{ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ}
BEGIN
nhap;
x[0]:=0;
assign(f,fo);
rewrite(f);
tim(1);
close(f)
END.
free_pascal- Mouse
- Tổng số bài gửi : 18
Join date : 09/10/2011
Age : 27
Đến từ : USIT
Trang 1 trong tổng số 1 trang
Permissions in this forum:
Bạn không có quyền trả lời bài viết
|
|