結果

問題 No.357 品物の並び替え (Middle)
ユーザー Kutimoti_TKutimoti_T
提出日時 2018-06-20 18:10:22
言語 C++11
(gcc 13.3.0)
結果
AC  
実行時間 8 ms / 5,000 ms
コード長 572 bytes
コンパイル時間 1,260 ms
コンパイル使用メモリ 159,468 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-06-30 17:26:17
合計ジャッジ時間 1,964 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 18
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using i64 = long long;

int N,M;

i64 score[14][14];

i64 dp[1 << 14];
int main(){
  cin >> N >> M;
  for(int i = 0;i < M;i++){
    i64 a,b,c;
    cin >> a >> b >> c;
    score[a][b] = c;
  }

  for(int s = 1;s < (1 << N);s++){
    for(int p = 0;p < N;p++){
      int t = s & ~(1 << p);
      if(t == s) continue;
      i64 res = 0;
      for(int i = 0;i < N;i++){
        if(t & (1 << i)){
          res += score[i][p];
        }
      }
      dp[s] = max(dp[s],dp[t] + res);
    }
  }

  cout << dp[(1 << N) - 1] << endl;
}
0