結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 10 ms
5,376 KB
testcase_10 AC 5 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 48 ms
5,376 KB
testcase_13 AC 24 ms
5,376 KB
testcase_14 AC 15 ms
5,376 KB
testcase_15 AC 3 ms
5,376 KB
testcase_16 AC 9 ms
5,376 KB
testcase_17 AC 5 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

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