結果

問題 No.357 品物の並び替え (Middle)
ユーザー amaridekinaiamaridekinai
提出日時 2019-09-17 17:54:52
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,127 bytes
コンパイル時間 1,329 ms
コンパイル使用メモリ 165,560 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-21 19:45:29
合計ジャッジ時間 2,438 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 AC 2 ms
4,380 KB
testcase_16 WA -
testcase_17 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAX_N = 1 << 15;
const int MAX_V = 15;
int dp[MAX_N];
int pre[MAX_V][MAX_V];

void chmax(int &a, int b){ if( a < b){ swap(a,b); } return ;}

int main(){
int N,M;  cin >> N >> M;

 for(int i = 0; i < MAX_V; i++){
  for(int j = 0; j < MAX_V; j++){
   pre[i][j] = 0;}}//初期化
  
   for(int i = 0; i < MAX_N; i++){ dp[i] = 0;}
  
  for(int i = 0; i < M; i++){
    int a,b,score; cin >> a >> b >> score;
    pre[a][b] = score;}
  
  for(int mask = 0; mask < (1<<N); mask++){
    //すでに mask(2進数)までは並び終わっている状況を考える
     for(int a = 0; a < N; a++){
      //まだaが並んでいない時、これを並べることを考える
       if( !(mask>>a & 1) ){
         int res = 0;
         for(int b = 0; b < N; b++){
           
             //すでに後ろにbが並んでいたら、それだけのscoreを受ける。
             res += pre[a][b];}
             
      chmax(dp[mask|1<<a], dp[mask]+res);}
         }
       }
      
     
  
  cout << dp[(1<<N)-1] << endl; return 0;}
         
        
  
0