結果

問題 No.357 品物の並び替え (Middle)
ユーザー tokkakatokkaka
提出日時 2016-07-29 23:07:31
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 18 ms / 5,000 ms
コード長 875 bytes
コンパイル時間 1,033 ms
コンパイル使用メモリ 95,116 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-24 12:22:55
合計ジャッジ時間 1,643 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <functional>
#include <tuple>
#include <climits>
#include <algorithm>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <set>
#include <iomanip>

using namespace std;

int main()
{
    int N, M;
    cin >> N >> M;
    vector<int> item1(M), item2(M), score(M);
    for(int i=0; i<M; i++)
        cin >> item1[i] >> item2[i] >> score[i];
    vector<int> dp(1<<N, 0);
    dp[0] = 0;
    for(int i=0; i<(1<<N)-1;i++) {
        for(int j=0; j<N; j++) {
            if((i&(1<<j)) != 0) continue;
            int total_score = 0;
            for(int k=0; k<M; k++)
                if(item1[k]==j && (i&(1<<item2[k])) == 0) total_score += score[k];
            dp[i | (1<<j)] = std::max(dp[i|(1<<j)], dp[i]+total_score);
        }
    }
    cout << dp[(1<<N)-1] << endl;
}
0