結果

問題 No.90 品物の並び替え
ユーザー kakeyamaykakeyamay
提出日時 2019-07-01 22:50:09
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 501 bytes
コンパイル時間 1,956 ms
コンパイル使用メモリ 203,512 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-25 10:10:43
合計ジャッジ時間 2,758 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 WA -
testcase_02 AC 2 ms
4,376 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
権限があれば一括ダウンロードができます

ソースコード

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)]=sc;
		}
	}
	int ans = dp[(1<<N)-1];
	std::cout << ans << std::endl;
}
0