結果

問題 No.357 品物の並び替え (Middle)
ユーザー albicillaalbicilla
提出日時 2017-08-15 03:58:41
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 56 ms / 5,000 ms
コード長 758 bytes
コンパイル時間 2,618 ms
コンパイル使用メモリ 160,988 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-21 11:31:13
合計ジャッジ時間 3,170 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 3 ms
6,940 KB
testcase_05 AC 2 ms
6,944 KB
testcase_06 AC 2 ms
6,944 KB
testcase_07 AC 2 ms
6,944 KB
testcase_08 AC 3 ms
6,944 KB
testcase_09 AC 12 ms
6,940 KB
testcase_10 AC 6 ms
6,940 KB
testcase_11 AC 3 ms
6,940 KB
testcase_12 AC 56 ms
6,944 KB
testcase_13 AC 29 ms
6,944 KB
testcase_14 AC 18 ms
6,940 KB
testcase_15 AC 2 ms
6,948 KB
testcase_16 AC 11 ms
6,940 KB
testcase_17 AC 7 ms
6,944 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