結果

問題 No.357 品物の並び替え (Middle)
ユーザー uenokuuenoku
提出日時 2017-01-08 02:49:23
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 7 ms / 5,000 ms
コード長 1,089 bytes
コンパイル時間 676 ms
コンパイル使用メモリ 70,692 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-22 17:19:48
合計ジャッジ時間 1,731 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
using namespace std;
typedef long long int lli;
lli MOD = 1000000007;
lli dp[1 << 15] = {};
int main()
{
    int n, m;
    cin >> n >> m;
    int f[200], l[200], c[200];
    lli val[15][15] = {};
    rep(i, m)
    {
        cin >> f[i] >> l[i] >> c[i];
        val[f[i]][l[i]] = c[i];
    }
    lli ans = 0;
    for (int i = 0; i < 1 << n; i++) {
        vector<int> g;
        rep(j, n)
        {
            if ((i >> j) & 1)
                g.push_back(j);
        }
        rep(j, n)
        {
            if (!((i >> j) & 1)) {
                int va = 0;
                for (auto k : g) {
                    va += (val[k][j]);
                }
                //                cout << va << endl;
                dp[i + (1 << j)] = max(dp[i] + va, dp[i + (1 << j)]);
            }
        }
        ans = max(dp[i], ans);
    }
    cout << ans << endl;
}
0