WA 88 pts 求调
查看原帖
WA 88 pts 求调
908514
DHT666楼主2025/1/9 12:16

rt,谢谢

#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
using namespace std;

typedef long long LL;

const LL N = 20;

LL n, m;
LL Map[N][N];
LL dp[1 << N][N];

int main() {
//	freopen(".in", "r", stdin);
//	freopen(".out", "w", stdout);

	scanf("%lld%lld", &n, &m);
	for(LL i = 1; i <= m; i++) {
		LL x, y, z;
		scanf("%lld%lld%lld", &x, &y, &z);
		x++, y++;
		Map[x][y] = z;
	}

	memset(dp, -0x3f, sizeof dp);
	LL res = 0;
	for(LL i = 0; i < (1 << n); i++) {
		if(!(i & 1)) continue;
		for(LL j = 1; j <= n; j++) {
			if(!((i >> j - 1) & 1)) continue;
			dp[i][j] = 0;
			for(LL k = 1; k <= n; k++) {
				if(!((i >> k - 1) & 1)) continue;
				if(Map[k][j]) dp[i][j] = max(dp[i][j], dp[i ^ (1 << j - 1)][k] + Map[k][j]);
			}
			if(j == n && ((i >> n - 1) & 1)) res = max(res, dp[i][j]);
		}
	}

	printf("%lld", res);

	return 0;
}
2025/1/9 12:16
加载中...