请用python语言转换下面的c++代码:#includebitsstdc++husing namespace std;typedef long long ll;#define repixy forint i=x;i=y;++iint nmk;ll a20c2020dp11820res;vectorintsta;int countint x int s=0; whilex
import math
n, m, k = map(int, input().split()) a = list(map(int, input().split())) c = [[0]*n for _ in range(n)] dp = [[-math.inf]*n for _ in range(1<<n)] res = 0 sta = []
def count(x): s = 0 while x: if x & 1: s += 1 x >>= 1 return s
for _ in range(k): x, y, z = map(int, input().split()) c[x-1][y-1] = z
for i in range(n): dp[0][i] = 0 dp[1<<i][i] = a[i]
for i in range(1, (1<<n)): if count(i) == m: sta.append(i) for j in range(n): if not (i & (1<<j)): for k in range(n): if i & (1<<k): dp[i|(1<<j)][j] = max(dp[i|(1<<j)][j], dp[i][k] + a[j] + c[k][j])
sz = len(sta) for i in range(n): for j in range(sz): res = max(res, dp[sta[j]][i])
print(res
原文地址: https://www.cveoy.top/t/topic/iF34 著作权归作者所有。请勿转载和采集!