結果

問題 No.357 品物の並び替え (Middle)
ユーザー ありあり
提出日時 2023-02-07 12:08:39
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 858 bytes
コンパイル時間 747 ms
コンパイル使用メモリ 82,080 KB
実行使用メモリ 4,500 KB
最終ジャッジ日時 2023-09-18 19:50:29
合計ジャッジ時間 1,778 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}
0