Originally posted by anonymous1
View Post
Xin cảm ơn.
program test; var a,b,c:array[0..33] of integer; tong,n,chlmin,s,dem,so:integer; {-------------------------------------------} procedure nhap; var i:integer; begin writeln('Nhap n: '); readln(n); tong:=0; writeln('Nhap mang: '); for i:=0 to n-1 do begin readln(a[i]); b[i]:=a[i]; tong:=tong+a[i]; end; end; {----------------------------------------------} procedure xeptagdan; var i,j,z:integer; begin for i:=0 to n-2 do for j:=i+1 to n-1 do if b[i]>b[j] then begin z:=b[i]; b[i]:=b[j]; b[j]:=z; end; end; {--------------------------------------------} procedure chenhlechmin; var w1,w2,i:integer; begin w1:=b[n-1]; w2:=0; for i:=n-2 downto 0 do if w1<w2 then w1:=w1+b[i] else w2:=w2+b[i]; chlmin:=abs(w1-w2); end; {--------------------------------------------------} {------------------------------------------------------} procedure xuly(m:integer); var j:longint; begin for j:=m to n-1 do if s+a[j]<=so then begin s:=s+a[j]; if s=so then inc(dem) else if j<n-1 then xuly(j+1); s:=s-a[j]; end; end; {------------------------------------------} begin nhap; s:=0; dem:=0; xeptagdan; chenhlechmin; so:=(tong-chlmin)div 2; xuly(0); writeln('Ket qua'); writeln(chlmin,' ',dem); readln; end.
Leave a comment: