結果
問題 | No.519 アイドルユニット |
ユーザー |
|
提出日時 | 2017-05-28 21:55:00 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 873 bytes |
コンパイル時間 | 748 ms |
コンパイル使用メモリ | 77,372 KB |
実行使用メモリ | 81,536 KB |
最終ジャッジ日時 | 2024-09-21 15:24:43 |
合計ジャッジ時間 | 5,171 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | TLE * 1 -- * 33 |
ソースコード
#include <iostream>#include <algorithm>#include <string>#include <vector>using namespace std;void updmax(int &x, int y) {x = std::max(x, y);}int main() {int n;std::cin >> n;std::vector<std::vector<int>> cost(n, std::vector<int>(n));for (int i = 0; i < n; i++) {for (int j = 0; j < n; j++) {std::cin >> cost[i][j];}}constexpr int INF = 1e9;std::vector<int> dp(1 << n, -INF);dp[0] = 0;std::vector<bool> ok(1 << n);ok[0] = true;for (int i = 1; i < 1 << n; i++) {ok[i] = !ok[i & i - 1];}for (int i = 0; i < 1 << n; i++) {if (!ok[i]) {continue;}for (int j = 0; j < n; j++) {if (i >> j & 1) {continue;}for (int k = j + 1; k < n; k++) {if (i >> k & 1) {continue;}updmax(dp[i | 1 << j | 1 << k], dp[i] + cost[j][k]);}}}std::cout << dp[(1 << n) - 1] << std::endl;}