結果

問題 No.357 品物の並び替え (Middle)
ユーザー latte0119latte0119
提出日時 2016-04-01 23:54:05
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 50 ms / 5,000 ms
コード長 932 bytes
コンパイル時間 1,638 ms
コンパイル使用メモリ 158,280 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-10 08:19:24
合計ジャッジ時間 2,554 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;

#define int long long
typedef pair<int,int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
template<class T,class U>inline void chmin(T &t,U f){if(t>f)t=f;}
template<class T,class U>inline void chmax(T &t,U f){if(t<f)t=f;}

int dp[1<<14];
int N,M;
int A[11111],B[11111],C[11111];

signed main(){
    cin>>N>>M;
    rep(i,M)cin>>A[i]>>B[i]>>C[i];

    rep(i,1<<N){
        rep(j,N){
            if(i>>j&1)continue;
            int add=0;
            rep(k,M)if((i>>A[k]&1)&&B[k]==j)add+=C[k];
            chmax(dp[i|(1<<j)],dp[i]+add);
        }
    }
    cout<<dp[(1<<N)-1]<<endl;
    return 0;
}
0