結果

問題 No.357 品物の並び替え (Middle)
ユーザー albicillaalbicilla
提出日時 2017-08-15 03:46:06
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 755 bytes
コンパイル時間 1,794 ms
コンパイル使用メモリ 161,024 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-21 11:30:47
合計ジャッジ時間 2,561 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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>
using namespace std;
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define rep(i,b) FOR(i,0,b)
#define INF 1e9
#define dump(x) cerr<<#x<<"="<<x<<endl

int N,M;

bool contain(int mask,int bit){
  if(mask&(1<<bit)!=0)return true;
  return false;
}
int dp[(1<<15)];
int main(){
  cin>>N>>M;
  vector<int> score(M);
  vector<pair<int,int>> item(M);

  rep(i,M)cin>>item[i].first>>item[i].second>>score[i];

  for(int mask=1;mask<(1<<N);mask++){
    for(int i=0;i<N;i++){
      if(!contain(mask,i)){
        int sum=0;
        for(int j=0;j<M;j++){
          if(contain(mask,item[j].first)&&i==item[j].second)sum+=score[j];
        }
        dp[mask|(1<<i)]=max(dp[mask|(1<<i)],dp[mask]+sum);
      }
    }
  }
  cout<<dp[(1<<N)-1]<<endl;
}
0