結果

問題 No.90 品物の並び替え
ユーザー oxyshoweroxyshower
提出日時 2019-04-16 14:47:14
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 769 bytes
コンパイル時間 3,644 ms
コンパイル使用メモリ 173,064 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-22 07:03:19
合計ジャッジ時間 2,827 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
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 -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#define int long long

int G[10][10];

signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);

  int n,m; cin >> n >> m;

  for(int i = 0; i < m; i++){
    int a,b,c; cin >> a >> b >> c;
    G[a][b] = c;
  }

  int ans = 0;
  vector< vector<int> > dp(1 << n,vector<int> (n,-1));
  function< int(int,int) > rec =
  [&](int S,int u){
    if(__builtin_popcount(S) == n) return 0LL;
    if(dp[S][u] != -1) return dp[S][u];

    int res = 0;
    for(int i = 0; i < n; i++){
      if(S == 0){
        res = max(res,rec(S | 1 << i,i));
      }
      else if(!(S >> i & 1) && G[u][i]){
        res = max(res,rec(S | 1 << i,i) + G[u][i]);
      }
    }
    return dp[S][u] = res;
  };
  cout << rec(0,0) << endl;

  return 0;
}
0