結果

問題 No.357 品物の並び替え (Middle)
ユーザー kotatsugamekotatsugame
提出日時 2020-02-23 17:46:19
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 8 ms / 5,000 ms
コード長 416 bytes
コンパイル時間 557 ms
コンパイル使用メモリ 67,864 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-18 12:15:23
合計ジャッジ時間 1,302 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 5 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 3 ms
5,376 KB
testcase_12 AC 8 ms
5,376 KB
testcase_13 AC 4 ms
5,376 KB
testcase_14 AC 5 ms
5,376 KB
testcase_15 AC 2 ms
5,376 KB
testcase_16 AC 3 ms
5,376 KB
testcase_17 AC 3 ms
5,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:7:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
    7 | main()
      | ^~~~

ソースコード

diff #

#include<iostream>
#include<algorithm>
using namespace std;
int N,M;
int S[14][14];
int dp[1<<14];
main()
{
	cin>>N>>M;
	for(int i=0;i<M;i++)
	{
		int u,v,s;cin>>u>>v>>s;
		S[u][v]=s;
	}
	for(int i=0;i<1<<N;i++)
	{
		for(int j=0;j<N;j++)
		{
			if(i>>j&1)continue;
			int now=dp[i];
			for(int k=0;k<N;k++)
			{
				if(i>>k&1)now+=S[k][j];
			}
			dp[i|1<<j]=max(dp[i|1<<j],now);
		}
	}
	cout<<dp[(1<<N)-1]<<endl;
}
0