結果

問題 No.357 品物の並び替え (Middle)
ユーザー odan3240odan3240
提出日時 2016-04-02 12:06:22
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 24 ms / 5,000 ms
コード長 1,024 bytes
コンパイル時間 697 ms
コンパイル使用メモリ 73,768 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-10 08:15:42
合計ジャッジ時間 1,304 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>

using namespace std;
using ll = long long;

#define all(c) (c).begin(), (c).end()
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define pb(e) push_back(e)
#define mp(a, b) make_pair(a, b)
#define fr first
#define sc second

const ll INF=1e9;
const ll MOD=1e9+7;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int N,M;
int t1[200],t2[200],s[200];
int dp[1<<14];

int dfs(int S) {
    if(S+1==(1<<N)) return 0;
    int ret=0;
    if(dp[S]!=-1) return dp[S];
    rep(i,N) if(!(S>>i&1)) {
        int sum=0;
        rep(j,M) {
            if(t2[j]!=i) continue;
            if(S>>t1[j]&1) sum+=s[j];
        }
        ret=max(dfs(S|1<<i)+sum,ret);
    }
    return dp[S]=ret;
}

int main() {
    memset(dp,-1,sizeof(dp));
    cin>>N>>M;
    rep(i,M) cin>>t1[i]>>t2[i]>>s[i];
    cout<<dfs(0)<<endl;
    return 0;
}
0