結果
| 問題 |
No.90 品物の並び替え
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2019-07-12 13:42:23 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 5,000 ms |
| コード長 | 552 bytes |
| コンパイル時間 | 1,914 ms |
| コンパイル使用メモリ | 163,256 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-11-17 11:20:41 |
| 合計ジャッジ時間 | 2,118 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 9 |
ソースコード
#include "bits/stdc++.h"
using namespace std;
int main()
{
int N,M;
std::cin >> N >> M;
std::vector<std::vector<int>> table(N,std::vector<int>(N,0));
std::vector<int> dp(1<<N,0);
for(int i=0;i<M;++i){
int t1,t2,sc;
std::cin >> t1 >> t2 >> sc;
table[t1][t2]=sc;
}
for(int i=0;i<(1<<N);++i){
for(int j=0;j<N;++j){
if(i&(1<<j))continue;
int sc = dp[i];
for(int k=0;k<N;++k)
if(i&(1<<k))sc+=table[k][j];
dp[i|(1<<j)]=std::max(dp[i|(1<<j)],sc);
}
}
int ans = dp[(1<<N)-1];
std::cout << ans << std::endl;
return 0;
}