結果

問題 No.90 品物の並び替え
ユーザー machibito2machibito2
提出日時 2017-03-26 12:49:10
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 916 bytes
コンパイル時間 1,444 ms
コンパイル使用メモリ 165,372 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-20 10:58:33
合計ジャッジ時間 2,121 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 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 2 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

#define INF 114514

int main()
{
	int n,m,rin[9][9];
	for (int i = 0; i < 9; ++i)
	{
		for (int j = 0; j < 9; ++j)
		{
			rin[i][j] = 0;
		}
	}
	cin >> n >> m;
	for (int i = 0; i < m; ++i)
	{
		int a,b,c;
		cin >> a >> b >> c;
		rin[a][b] = c;
	}
	int DP[(1<<9)][9];
	for (int i = 0; i < (1<<9); ++i)
	{
		for (int j = 0; j < 9; ++j)
		{
			DP[i][j] = 0;
		}
	}
	for (int i = 0; i < n; ++i)
	{
		DP[(1<<i)][0] = rin[0][i];
	}
	for (int i = 1; i < (1<<n); ++i)
	{
		for (int j = 0; j < n; ++j)
		{
			bitset<9> bits = i;
			bits[j] = 0;
			for (int k = 0; k < n; ++k)
			{
				if(bits[k])
				{
					DP[i][j] = max(DP[i][j],DP[bits.to_ulong()][k]);
				}
			}
			for (int k = 0; k < n; ++k)
			{
				if(bits[k])
				{
					DP[i][j] += rin[k][j];
				}
			}
		}
	}
	int ans = 0;
	for (int i = 0; i < n; ++i)
	{
		ans = max(ans,DP[(1<<n)-1][i]);
	}
	cout << ans << endl;
}
0