|
|
вернуться в форумWho know test 1? var x:array[1..20] of integer; y:array[1..20] of longint; min,s:longint; n,i,v:longint; procedure outit; var i:integer; s,c:longint; begin s:=0; for i:=1 to n do inc(s,x[i]*y[i]); c:=v-s; if c>s then s:=c-s else s:=s-c; if s<min then min:=s; end; procedure search(k:longint); var i:integer; begin if k>n then begin outit;exit;end; for i:=0 to 1 do begin x[k]:=i;search(k+1);end; end; begin readln(n); min:=0; v:=0; for i:=1 to n do read(y[i]); for i:=1 to n do begin min:=min+y[i]; end; v:=min; search(1); writeln(min); end. I think I'm right. Re: Who know test 1? program ural1005; var a:array[1..20]of boolean; w:array[1..20]of longint; i,j,k,n,m:longint; function dif:longint; var diff:longint; begin diff:=0; for i:=1 to n do if a[i] then inc(diff,w[i]) else dec(diff,w[i]); exit(diff); end; procedure dfs(i:longint); begin if i>n then begin if abs(dif)<m then m:=abs(dif); exit; end; a[i]:=true; dfs(i+1); a[i]:=false; dfs(i+1); end; begin readln(n); for i:=1 to n do readln(w[i]); m:=maxlongint; a[1]:=true; dfs(2); writeln(m); end. Me too Re: Who know test 1? not readln(w[i]); but read(w[i]); I had this mistake at the first time (because of spaces between numbers) |
|
|