|
|
вернуться в форумwhy wa test 7 ? Послано Charm 7 дек 2011 15:29 why WA 7 ? var n,k,t,p,sum,inf,c,k2,w:integer; a:array[0..25] of integer; d:array[0..5048576] of integer; i,j,q:integer; begin read(n); inf := maxint div 2; for i := 0 to n - 1 do read(a[i]); k := 1 shl n; k2 := k shl 1; for i := 1 to k do d[i] := inf; d[0] := 0; Dec(k); for i := 0 to k do begin if (d[i] = inf) then Continue; sum := 0; for j := 0 to n - 1 do begin t := i or (7 shl j); if (t > k) and (t < k2) then begin t := t shr 1; t := t and (not(1 shl (n - 3))); t := t or 1; end; if (t >= k2) then begin t := t shr 2; t := t and (not (1 shl (n - 3))); t := t and (not (1 shl (n - 2))); t := t or 3; end; sum := 0; for q := 0 to n - 1 do if (t shr q) and 1 = 0 then sum := sum + a[n - q - 1]; if d[t] > d[i] + sum then d[t] := d[i] + sum; c := d[k]; end; end; writeln(d[k]); end. |
|
|