結果

問題 No.357 品物の並び替え (Middle)
ユーザー okkuukenkenokkuukenken
提出日時 2019-04-06 10:42:41
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 879 bytes
コンパイル時間 414 ms
コンパイル使用メモリ 51,180 KB
実行使用メモリ 5,256 KB
最終ジャッジ日時 2023-09-05 21:22:58
合計ジャッジ時間 1,486 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
using namespace std;

const int MAX_N = 14, MAX_M = MAX_N * (MAX_N - 1);

int G[MAX_N][MAX_N];

void add_edge(int from, int to, int cost) {
	G[from][to] = cost;
}

int N, M;
int item1[MAX_M], item2[MAX_M], score[MAX_M];

int dp[1 << MAX_N];

void solve() {
	for (int i = 0; i < M; i++) {
		add_edge(item1[i], item2[i], score[i]);
	}

	sizeof(dp, -1, sizeof(dp));

	for (int S = 0; S < 1 << N; S++) {
		for (int t = 0; t < N; t++) {
			if (!(S << t & 1)) {
				int s = 0;
				for (int f = 0; f < N; f++) {
					if (S >> f & 1) {
						s += G[f][t];
					}
				}
				dp[S | 1 << t] = max(dp[S | 1 << t], dp[S] + s);
			}
		}
	}

	printf("%d\n", dp[(1 << N) - 1]);
}

int main() {
	scanf("%d %d", &N, &M);
	for (int i = 0; i < M; i++) {
		scanf("%d %d %d", &item1[i], &item2[i], &score[i]);
	}

	solve();
}
0