結果
| 問題 |
No.357 品物の並び替え (Middle)
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2017-04-08 12:02:52 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 23 ms / 5,000 ms |
| コード長 | 875 bytes |
| コンパイル時間 | 482 ms |
| コンパイル使用メモリ | 67,036 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-07-17 23:39:48 |
| 合計ジャッジ時間 | 1,418 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 18 |
ソースコード
#include <iostream>
#include <algorithm>
#include <cstdio>
using namespace std;
const int MAX_N = 14;
int dp[1 << MAX_N] = {0};
int score_tbl[MAX_N][MAX_N] = {0};
int main(){
int n,m;
cin >> n >> m;
int a,b,score,sub_total=0;
for(int i = 0; i < m; i++){
cin >> a >> b >> score;
score_tbl[a][b] = score;
}
for(int i = 0; i < 1 << n; i++){
for(int j = 0; j < n; j++){
for(int k = 0; k < n; k++){
if(((i >> j) & 1) && !((i >> k) & 1)){
for(int l = 0; l < n;l++){
if(i >> l & 1) sub_total += score_tbl[l][k];
}
dp[i | 1 << k] = max(dp[i | 1 << k],dp[i] + sub_total);
sub_total = 0;
}
}
}
}
cout << dp[(1 << n)-1] << endl;
return 0;
}