From 94f49ef11037832a173d268ca932fe34cf78b472 Mon Sep 17 00:00:00 2001 From: Raphael McSinyx Date: Wed, 9 Nov 2016 11:02:27 +0700 Subject: Thêm kì thi thử Duyên Hải MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- others/mkcal/llgc2m.pas | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100755 others/mkcal/llgc2m.pas (limited to 'others/mkcal/llgc2m.pas') diff --git a/others/mkcal/llgc2m.pas b/others/mkcal/llgc2m.pas new file mode 100755 index 0000000..3fc8ef2 --- /dev/null +++ b/others/mkcal/llgc2m.pas @@ -0,0 +1,44 @@ +uses math; +var + f : text; + n, i : byte; + a, b, c, c0 : array[1..255] of byte; + d : array[1..255] of boolean; + out : cardinal; +procedure libgc2m(m : byte; o0, o1 : cardinal); + var j : byte; + begin + if m > 0 then begin + for j := 1 to n do + if d[j] then begin + d[j] := false; + c[n - m + 1] := j; + libgc2m(m - 1, o0 + a[j], max(o0 + a[j], o1) + b[j]); + d[j] := true; + end + end else + if (o1 < out) or (out = 0) then begin + out := o1; + for j := 1 to n do c0[j] := c[j] + end + end; +begin + assign(f, 'llgc2m.inp'); + reset(f); + readln(f, n); + for i := 1 to n do read(f, a[i], b[i]); + close(f); + for i := 1 to n do d[i] := true; + out := 0; + for i := 1 to n do begin + d[i] := false; + c[1] := i; + libgc2m(n - 1, a[i], a[i] + b[i]); + d[i] := true + end; + assign(f, 'llgc2m.out'); + rewrite(f); + writeln(f, out); + for i := 1 to n do write(f, c0[i], ' '); + close(f) +end. -- cgit 1.4.1