about summary refs log tree commit diff
path: root/others/other/chonso1.pas
diff options
context:
space:
mode:
authorRaphael McSinyx <vn.mcsinyx@gmail.com>2017-08-14 20:55:39 +0700
committerRaphael McSinyx <vn.mcsinyx@gmail.com>2017-08-14 20:55:39 +0700
commitdbeda825d396deff88ac6754b20c084bd77510b7 (patch)
treeb19034a50cfcec1e3675d57c4da1ee6314177fb8 /others/other/chonso1.pas
parentdf20bbbebb8d5951607560d358c1a19388743113 (diff)
downloadcp-dbeda825d396deff88ac6754b20c084bd77510b7.tar.gz
Add others/other/{chonso1.pas,khaosat.py}
Diffstat (limited to 'others/other/chonso1.pas')
-rw-r--r--others/other/chonso1.pas60
1 files changed, 60 insertions, 0 deletions
diff --git a/others/other/chonso1.pas b/others/other/chonso1.pas
new file mode 100644
index 0000000..7e10400
--- /dev/null
+++ b/others/other/chonso1.pas
@@ -0,0 +1,60 @@
+var
+  f: text;
+  n, k, i, j: uint8;
+  max, count: uint64;
+  a: array[1..10, 1..10] of uint64;
+  avail: array[1..10] of boolean = (true, true, true, true, true,
+                                    true, true, true, true, true);
+
+
+procedure chonso1(
+  depth, len: uint8;
+  sum: uint64
+);
+
+  var
+    i: uint8;
+
+  begin
+    if len = k then
+      begin
+        if sum > max then
+          begin
+            max := sum;
+            count := 1
+          end
+        else if sum = max then
+          inc(count);
+        exit
+      end;
+
+    for i := 1 to n do
+      if avail[i] then
+        begin
+          avail[i] := false;
+          chonso1(depth + 1, len + 1, sum + a[depth, i]);
+          avail[i] := true
+        end;
+
+    if k - len <= n - depth then
+      chonso1(depth + 1, len, sum);
+  end;
+
+
+begin
+  assign(f, 'CHONSO1.INP');
+  reset(f);
+  readln(f, n, k);
+  for i := 1 to n do
+    for j := 1 to n do
+      read(f, a[i, j]);
+  close(f);
+
+  max := 0;
+  chonso1(1, 0, 0);
+
+  assign(f, 'CHONSO1.OUT');
+  rewrite(f);
+  writeln(f, max, ' ', count);
+  close(f)
+end.