結果
| 問題 |
No.519 アイドルユニット
|
| コンテスト | |
| ユーザー |
ふーらくたる
|
| 提出日時 | 2017-05-28 23:48:05 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,969 bytes |
| コンパイル時間 | 854 ms |
| コンパイル使用メモリ | 94,380 KB |
| 実行使用メモリ | 179,840 KB |
| 最終ジャッジ日時 | 2024-09-21 16:01:12 |
| 合計ジャッジ時間 | 5,252 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | TLE * 1 -- * 33 |
ソースコード
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <stack>
#include <queue>
#include <functional>
#include <algorithm>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <vector>
#include <array>
#include <tuple>
#include <utility>
#include <numeric>
#include <iomanip>
#include <cctype>
#include <cmath>
#include <assert.h>
#include <cstdlib>
#include <list>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using PII = pair<int, int>;
using PLL = pair<ll, ll>;
template<typename T1, typename T2> ostream& operator<<(ostream& s, const pair<T1, T2>& p) {
return s << "(" << p.first << ", " << p.second << ")";
}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
s << "[";
for (int i = 0; i < v.size(); i++) s << (i == 0 ? "" : ", ") << v[i];
s << "]";
return s;
}
#define ALL(a) (a).begin(), (a).end()
int size[1 << 24], dp[1 << 24], cost[1 << 24];
int table[24][24];
int main() {
int n;
cin >> n;
for (int r = 0; r < n; r++) {
for (int c = 0; c < n; c++) {
cin >> table[r][c];
}
}
for (int mask = 0; mask < (1 << n); mask++) {
for (int i = 0; i < n; i++) {
if ((mask >> i) & 1) size[mask]++;
}
}
vector<PII> foo;
for (int a = 0; a < n; a++) {
for (int b = a + 1; b < n; b++) {
cost[(1 << a) | (1 << b)] = table[a][b];
foo.push_back(make_pair((1 << a) | (1 << b), table[a][b]));
}
}
memset(dp, -1, sizeof(dp));
dp[(1 << n) - 1] = 0;
for (int mask = (1 << n) - 1; mask > 0; mask--) {
if (dp[mask] < 0 || size[mask] % 2 == 1) continue;
for (PII& f : foo) {
if ((mask & f.first) == f.first) {
dp[mask ^ f.first] = max(dp[mask ^ f.first], dp[mask] + f.second);
}
}
}
cout << dp[0] << endl;
return 0;
}
ふーらくたる