結果

問題 No.357 品物の並び替え (Middle)
ユーザー tailstails
提出日時 2016-04-01 22:41:47
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 7 ms / 5,000 ms
コード長 963 bytes
コンパイル時間 530 ms
コンパイル使用メモリ 69,484 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-10 07:32:37
合計ジャッジ時間 1,263 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

// http://yukicoder.me/submissions/31211

#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)

using namespace std;
typedef long long int ll;
typedef vector<int> VI;
typedef pair<int, int> PI;
const double EPS=1e-9;

const int N = 14;
int dp[1 << N];
int mat[N][N];

int main(void){
  int n, m;
  cin >> n >> m;
  REP (i, 0, m) {
    int i1, i2, s;
    cin >> i1 >> i2 >> s;
    mat[i1][i2] = s;
  }
  REP(bits, 0, 1 << n) {
    int ma = 0;
    REP(i, 0, n) {
      if ((bits & (1 << i)) == 0) {
    continue;
      }
      int gain = 0;
      REP (j, 0, n) {
    if ((bits & (1 << j)) == 0) {
      continue;
    }
    gain += mat[j][i];
      }
      ma = max(dp[bits ^ (1 << i)] + gain, ma);
    }
    dp[bits] = ma;
  }
  cout << dp[(1 << n) - 1] << endl;
}
0