結果

問題 No.357 品物の並び替え (Middle)
ユーザー 紙ぺーぱー紙ぺーぱー
提出日時 2016-04-02 01:39:19
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 3 ms / 5,000 ms
コード長 671 bytes
コンパイル時間 1,507 ms
コンパイル使用メモリ 163,936 KB
実行使用メモリ 4,396 KB
最終ジャッジ日時 2023-08-01 07:39:23
合計ジャッジ時間 2,307 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
int n,m,a,b,c,go[14][14], pt[14][1<<14],dp[1<<14];
int main(){
  scanf("%d%d",&n,&m);
  for(int i=0;i<m;i++){
    scanf("%d%d%d",&a,&b,&c);
    go[a][b]=c;pt[a][0]+=c;
  }
  for (int i = 0; i < n; i++){
    int high = 1;
    int hst = 0;
    for (int j = 1; j < 1 << n; j++){
        if (!(j >> i & 1))
          pt[i][j] = pt[i][j ^ high] - go[i][hst];
        if(j+1==high<<1){high<<=1;hst++;}
    }
  }
  for (int i = 0; i < 1 << n; i++){
    for (int j = 0; j < n; j++){
        if ((i >> j & 1)) continue;
        dp[i | (1 << j)] = max(dp[i | (1 << j)], dp[i] + pt[j][i]);
    }
  }
  printf("%d\n",dp[(1 << n) - 1]);
}
0