結果

問題 No.357 品物の並び替え (Middle)
コンテスト
ユーザー FF256grhy
提出日時 2016-04-02 03:07:45
言語 C++11
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=gnu++11 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
RE  
実行時間 -
コード長 695 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 351 ms
コンパイル使用メモリ 40,320 KB
実行使用メモリ 6,400 KB
最終ジャッジ日時 2026-04-18 19:18:14
合計ジャッジ時間 2,621 ms
ジャッジサーバーID
(参考情報)
judge3_1 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 17 RE * 1
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <stdio.h>

int score[14][14], dp[1 << 14], queue[1 << 14], get = 0, set = 0;

int main() {
	int n, m, i, j;
	scanf("%d%d", &n, &m);
	for(i = 0; i < m; i++) {
		int a, b, c;
		scanf("%d%d%d", &a, &b, &c);
		score[a][b] = c;
	}
	
	//dp[0] = 0;
	//queue[0] = 0;
	set++;
	
	while(get != set) {
		for(i = 0; i < n; i++) {
			if( ( queue[get] & (1 << i) ) == 0 ) {
				int next = queue[get] + (1 << i);
				int s = dp[ queue[get] ];
				for(j = 0; j < n; j++) {
					if( queue[get] & (1 << j) ) { s += score[j][i]; }
				}
				if(dp[next] == 0) { queue[set] = next; set++; }
				dp[next] = dp[next] < s ? s : dp[next];
			}
		}
		get++;
	}
	
	printf("%d\n", dp[(1 << n) - 1]);
	
	return 0;
}
0