結果

問題 No.357 品物の並び替え (Middle)
ユーザー takune1024takune1024
提出日時 2017-11-24 23:53:53
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 7 ms / 5,000 ms
コード長 798 bytes
コンパイル時間 544 ms
コンパイル使用メモリ 66,972 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-18 05:33:04
合計ジャッジ時間 1,631 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <queue>
#include <utility>
using namespace std;

typedef pair<int, int> P;
typedef unsigned long long ll;

const int inf = 999999999;
const int mod = 1000000007;

int dp[1 << 14];

int main(){
	int n, m;
	cin >> n >> m;
	int d[n][n];
	for(int i = 0; i < n; i++){
		for(int j = 0; j < n; j++){
			d[i][j] = 0;
		}
	}
	for(int i = 0; i < m; i++){
		int x, y, z;
		cin >> x >> y >> z;
		d[x][y] = z;
	}
	for(int S = 0; S < (1 << n); S++){
		for(int i = 0; i < n; i++){
			if((S & (1 << i)) == 0){
				int t = 0;
				for(int j = 0; j < n; j++){
					if(S & (1 << j)){
						t += d[j][i];
					}
				}
				dp[S | (1 << i)] = max(dp[S | (1 << i)], dp[S] + t);
			}
		}
	}
	cout << dp[(1 << n) - 1] << endl;
	return 0;
}
0