結果

問題 No.357 品物の並び替え (Middle)
ユーザー kakeyamaykakeyamay
提出日時 2019-07-02 07:41:32
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 7 ms / 5,000 ms
コード長 524 bytes
コンパイル時間 3,885 ms
コンパイル使用メモリ 202,944 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-26 12:09:15
合計ジャッジ時間 3,952 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 5 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 7 ms
4,376 KB
testcase_13 AC 4 ms
4,380 KB
testcase_14 AC 4 ms
4,376 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 3 ms
4,376 KB
testcase_17 AC 3 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

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;
}
0