結果

問題 No.357 品物の並び替え (Middle)
ユーザー 👑 はまやんはまやんはまやんはまやん
提出日時 2017-02-27 03:11:13
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 7 ms / 5,000 ms
コード長 551 bytes
コンパイル時間 4,691 ms
コンパイル使用メモリ 163,632 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-02 10:34:07
合計ジャッジ時間 3,043 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<b;i++)





int N, M;
int S[14][14];
//-----------------------------------------------------------------
int dp[1 << 14];
int main() {
	cin >> N >> M;
	rep(i, 0, M) {
		int a, b, c;
		cin >> a >> b >> c;
		S[a][b] = c;
	}

	rep(ma, 0, 1 << N) {
		rep(i, 0, N) if (!(ma & (1 << i))) {
			int mama = ma + (1 << i);
			int point = 0;
			rep(j, 0, N) if (ma & (1 << j)) point += S[j][i];
			dp[mama] = max(dp[mama], dp[ma] + point);
		}
	}

	cout << dp[(1 << N) - 1] << endl;
}
0