結果
| 問題 |
No.357 品物の並び替え (Middle)
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2023-02-07 12:08:39 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 858 bytes |
| コンパイル時間 | 687 ms |
| コンパイル使用メモリ | 83,860 KB |
| 実行使用メモリ | 6,948 KB |
| 最終ジャッジ日時 | 2024-07-05 09:25:11 |
| 合計ジャッジ時間 | 1,407 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | WA * 18 |
ソースコード
#include <iostream>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <algorithm>
#include <numeric>
#include <queue>
#include <cassert>
#include <cmath>
#include <bitset>
using namespace std;
int n, m;
long long a[20][20];
long long dp[20000];
void chmax(long long &a, long long b) {
a = max(a, b);
}
int main() {
cin >> n >> m;
for (int k = 0; k < m; k++) {
int i, j;
cin >> i >> j;
cin >> a[i][j];
}
for (int s = 0; s < (1<<n); s++)
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++)
if (!(s&(1<<i)) && (s&(1<<j))) {
if (i < j) chmax(dp[s|(1<<i)], dp[s] + (a[i][j]));
if (j < i) chmax(dp[s|(1<<i)], dp[s] + (a[i][j]));
}
//for (int s = 0; s < (1<<n); s++) cout << "dp[" << bitset<4>(s) << "] = " << dp[s] << endl;
cout << dp[(1<<n)-1] << endl;
}