結果
| 問題 |
No.357 品物の並び替え (Middle)
|
| コンテスト | |
| ユーザー |
momoyuu
|
| 提出日時 | 2023-03-24 03:20:55 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 8 ms / 5,000 ms |
| コード長 | 541 bytes |
| コンパイル時間 | 2,973 ms |
| コンパイル使用メモリ | 250,832 KB |
| 実行使用メモリ | 6,948 KB |
| 最終ジャッジ日時 | 2024-09-18 15:50:16 |
| 合計ジャッジ時間 | 4,079 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 18 |
ソースコード
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int main(){
int n,m;
cin>>n>>m;
vector<vector<int> >a(n,vector<int>(n,0));
for(int i = 0;i<m;i++){
int u,v,c;
cin>>u>>v>>c;
a[u][v] = c;
}
vector<int> dp(1<<n,0);
for(int i = 0;i<1<<n;i++){
for(int j = 0;j<n;j++)if(~i>>j&1){
int now = 0;
for(int k = 0;k<n;k++) if(i>>k&1) now += a[k][j];
dp[i|1<<j] = max(dp[i|1<<j],dp[i]+now);
}
}
cout<<dp[(1<<n)-1]<<endl;
}
momoyuu