結果
問題 |
No.519 アイドルユニット
|
ユーザー |
![]() |
提出日時 | 2017-05-29 02:26:05 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
TLE
(最新)
AC
(最初)
|
実行時間 | - |
コード長 | 1,336 bytes |
コンパイル時間 | 661 ms |
コンパイル使用メモリ | 85,604 KB |
実行使用メモリ | 40,008 KB |
最終ジャッジ日時 | 2024-10-02 07:35:17 |
合計ジャッジ時間 | 5,064 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | TLE * 1 -- * 33 |
ソースコード
#include <cstdio> #include <cassert> #include <cmath> #include <cstring> #include <algorithm> #include <iostream> #include <vector> #include <functional> #include <utility> #include <set> #include <map> #include <queue> #define _rep(_1, _2, _3, _4, name, ...) name #define rep2(i, n) rep3(i, 0, n) #define rep3(i, a, b) rep4(i, a, b, 1) #define rep4(i, a, b, c) for (int i = int(a); i < int(b); i += int(c)) #define rep(...) _rep(__VA_ARGS__, rep4, rep3, rep2, _)(__VA_ARGS__) using namespace std; using i16 = short; using i64 = long long; using u32 = unsigned; using u64 = unsigned long long; using f80 = long double; const int N_MAX = 24; i16 memo[1 << N_MAX]; int cost[N_MAX][N_MAX]; int rec(int state) { if (!state) return 0; if (memo[state] == 0) { int i = __builtin_ctz(state); int s = state & (state - 1), t = s; int best = 0; for (; t; t &= t - 1) { int j = __builtin_ctz(t); best = max(best, cost[i][j] + rec(s ^ (1 << j))); } memo[state] = best; } return memo[state]; } void solve() { int N; while (~scanf("%d", &N)) { rep(i, N) rep(j, N) scanf("%d", &cost[i][j]); printf("%d\n", rec((1 << N) - 1)); } } int main() { clock_t beg = clock(); solve(); clock_t end = clock(); fprintf(stderr, "%.3f sec\n", double(end - beg) / CLOCKS_PER_SEC); return 0; }