結果

問題 No.357 品物の並び替え (Middle)
ユーザー hashiryohashiryo
提出日時 2019-06-06 15:27:38
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 824 bytes
コンパイル時間 1,683 ms
コンパイル使用メモリ 172,784 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-26 01:41:12
合計ジャッジ時間 2,583 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include<bits/stdc++.h>

#define debug(x) cerr << #x << ": " << x << '\n'
#define debugArray(x,n) for(long long hoge = 0; (hoge) < (n); ++ (hoge)) cerr << #x << "[" << hoge << "]: " << x[hoge] << '\n'
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> vll;
const ll INF = INT_MAX;
const ll MOD = 1e9+7;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll N,M;cin>>N>>M;
  vector<tuple<ll,ll> > G[20];
  for(ll i=0;i<M;i++){
    ll a,b,s;cin>>a>>b>>s;
    G[b].emplace_back(make_tuple(a,s));
  }
  ll dp[1<<15];
  for(ll S=0;S<1<<N;S++){
    for(ll i=0;i<N;i++)if(!((S>>i)&1)){
      ll tmp=0;
      for(auto v:G[i])if((S>>get<0>(v))&1){
        tmp+=get<1>(v);
      }
      dp[S|(1<<i)]=max(dp[S|(1<<i)],dp[S]+tmp);
    }
  }
  cout<<dp[(1<<N)-1]<<endl;
  return 0;
}
0