結果
問題 | No.357 品物の並び替え (Middle) |
ユーザー |
|
提出日時 | 2020-07-31 08:38:44 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 11 ms / 5,000 ms |
コード長 | 425 bytes |
コンパイル時間 | 1,961 ms |
コンパイル使用メモリ | 192,784 KB |
最終ジャッジ日時 | 2025-01-12 08:34:51 |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 18 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:8:23: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 8 | int n,m; scanf("%d%d",&n,&m); | ~~~~~^~~~~~~~~~~~~~ main.cpp:11:33: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 11 | int u,v,c; scanf("%d%d%d",&u,&v,&c); | ~~~~~^~~~~~~~~~~~~~~~~~~
ソースコード
#include <bits/stdc++.h>#define rep(i,n) for(int i=0;i<(n);i++)using namespace std;int main(){int n,m; scanf("%d%d",&n,&m);int d[14][14]={};rep(i,m){int u,v,c; scanf("%d%d%d",&u,&v,&c);d[u][v]+=c;}int dp[1<<14]={};rep(S,1<<n){rep(u,n) if(S>>u&1) {int sum=0;rep(v,n) if(v!=u && S>>v&1) sum+=d[v][u];dp[S]=max(dp[S],dp[S&~(1<<u)]+sum);}}printf("%d\n",dp[(1<<n)-1]);return 0;}