結果

問題 No.357 品物の並び替え (Middle)
ユーザー h_nosonh_noson
提出日時 2016-04-07 14:32:17
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 9 ms / 5,000 ms
コード長 856 bytes
コンパイル時間 665 ms
コンパイル使用メモリ 59,828 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-14 22:23:48
合計ジャッジ時間 1,330 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

#define RREP(i,s,e) for (i = s; i >= e; i--)
#define rrep(i,n) RREP(i,n,0)
#define REP(i,s,e) for (i = s; i < e; i++)
#define rep(i,n) REP(i,0,n)
#define INF 100000000

typedef long long ll;

int dp[1<<14];
int score[14][14];
int n;

int solve(int x) {
    int i, j;
    if (dp[x] >= 0)
        return dp[x];
    rep (i,n) {
        if (x & (1<<i)) {
            int rest = x ^ (1<<i);
            int sum = 0;
            rep (j,n) if (rest & (1<<j)) sum += score[j][i];
            dp[x] = max(dp[x],solve(rest)+sum);
        }
    }
    return dp[x];
}

int main() {
    int i, m;
    cin >> n >> m;
    rep (i,m) {
        int x, y;
        cin >> x >> y;
        cin >> score[x][y];
    }
    fill(dp+1,dp+(1<<n),-1);
    cout << solve((1<<n)-1) << endl;
    return 0;
}
0