結果

問題 No.90 品物の並び替え
ユーザー ko_ki_leoko_ki_leo
提出日時 2015-10-12 09:31:37
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 637 bytes
コンパイル時間 1,379 ms
コンパイル使用メモリ 144,232 KB
実行使用メモリ 4,556 KB
最終ジャッジ日時 2023-09-28 12:37:41
合計ジャッジ時間 2,184 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,408 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;

int n, m;
int data[11][11];
int memo[11][1<<11][11];

int solve(int p, int bit, int pre){

  if(!p) return 0;
  if(~memo[p][bit][pre]) return memo[p][bit][pre];
  
  int ret = 0;
  for(int i=0;i<n;i++)
    if(!(bit & (1 << i)))
      ret = max(ret, solve(p-1, (bit | (1 << i)), i)+data[pre][i]);

  return memo[p][bit][pre] = ret;

}

int main(){

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

  memset(memo, -1, sizeof(memo));
  int ans = 0;
  for(int i=0;i<n;i++) ans = max(ans, solve(n, (1 << i), i));

  cout << ans << endl;

}
0