結果
問題 | No.357 品物の並び替え (Middle) |
ユーザー |
|
提出日時 | 2023-02-07 12:50:04 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 7 ms / 5,000 ms |
コード長 | 911 bytes |
コンパイル時間 | 749 ms |
コンパイル使用メモリ | 83,744 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-07-05 09:53:01 |
合計ジャッジ時間 | 1,236 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 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++) {if (!(s&(1<<i))) {long long ndp = dp[s];for (int j = 0; j < n; j++)if (s&(1<<j)) {if (i < j) ndp += a[i][j];else ndp += a[i][j];}chmax(dp[s|(1<<i)], ndp);}}//for (int s = 0; s < (1<<n); s++) cout << "dp[" << bitset<4>(s) << "] = " << dp[s] << endl;cout << dp[(1<<n)-1] << endl;}