結果

問題 No.357 品物の並び替え (Middle)
ユーザー Kutimoti_TKutimoti_T
提出日時 2018-03-06 13:27:36
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 8 ms / 5,000 ms
コード長 1,002 bytes
コンパイル時間 941 ms
コンパイル使用メモリ 72,376 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-17 23:54:24
合計ジャッジ時間 2,122 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <set>
#include <map>
#include <cmath>
using namespace std;
typedef long long i64;
typedef long double ld;
typedef pair<i64,i64> P;
#define rep(i,s,e) for(int i = (s);i <= (e);i++)

int n;
int m;

const int MAX = (1 << 15);

int dp[MAX];

int score[20][20];
int main()
{
    cin >> n >> m;
    rep(i,0,m - 1)
    {
        int a,b,s;
        cin >> a >> b >> s;
        score[a][b] = s;
    }

    rep(i,0,(1 << n) - 1)
    {
        rep(j,0,n - 1)
        {
            if((1 << j) & i)
            {
                int sub = i  & ~(1 << j);
                int res = 0;
                rep(k,0,n - 1)
                {
                    if(sub & (1 << k))
                    {
                        res += score[k][j];
                    }
                }

                dp[i] = max(dp[i] , dp[sub] + res);
            }
        }
    }

    cout << dp[(1 << n) - 1] << endl;
        
}
0