結果
問題 | No.519 アイドルユニット |
ユーザー |
|
提出日時 | 2018-01-26 14:18:25 |
言語 | D (dmd 2.109.1) |
結果 |
AC
|
実行時間 | 72 ms / 1,000 ms |
コード長 | 1,294 bytes |
コンパイル時間 | 694 ms |
コンパイル使用メモリ | 98,184 KB |
実行使用メモリ | 68,444 KB |
最終ジャッジ日時 | 2024-06-12 23:38:30 |
合計ジャッジ時間 | 2,291 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 34 |
ソースコード
import std.algorithm, std.conv, std.range, std.stdio, std.string; void readV(T...)(ref T t){auto r=readln.splitter;foreach(ref v;t){v=r.front.to!(typeof(v));r.popFront;}} T[] readArray(T)(size_t n){auto a=new T[](n),r=readln.splitter;foreach(ref v;a){v=r.front.to!T;r.popFront;}return a;} T[] readArrayM(T)(size_t n){auto a=new T[](n);foreach(ref v;a)v=readln.chomp.to!T;return a;} void main() { int n; readV(n); auto f = new int[][](n); foreach (i; 0..n) f[i] = readArray!int(n); auto memo = new int[](1<<n); memo[1..$] = -1; int search(int i) { if (memo[i] >= 0) return memo[i]; auto j = i.bsf, r = 0; foreach (k; j+1..n) if (i.bitTest(k)) r = max(r, search(i.bitReset(j).bitReset(k))+f[j][k]); return memo[i] = r; } writeln(search((1<<n)-1)); } pragma(inline) { pure bool bitTest(T)(T n, size_t i) { return (n & (T(1) << i)) != 0; } pure T bitSet(T)(T n, size_t i) { return n | (T(1) << i); } pure T bitReset(T)(T n, size_t i) { return n & ~(T(1) << i); } pure T bitComp(T)(T n, size_t i) { return n ^ (T(1) << i); } import core.bitop; pure int bsf(T)(T n) { return core.bitop.bsf(ulong(n)); } pure int bsr(T)(T n) { return core.bitop.bsr(ulong(n)); } pure int popcnt(T)(T n) { return core.bitop.popcnt(ulong(n)); } }