// No.90 品物の並び替え #include #include #include using namespace std; int main() { int N, M; cin >> N >> M; vector> table(N, vector(N, 0)); for (int i = 0; i < M; ++i) { int a, b, s; cin >> a >> b >> s; table[a][b] = s; } vector ord(N); for (int i = 0; i < N; ++i) ord[i] = i; int res = 0; do { int now = 0; for (int i = 0; i < N; ++i) { for (int j = i + 1; j < N; ++j) { now += table[ord[i]][ord[j]]; } } res = max(res, now); } while (next_permutation(ord.begin(), ord.end())); cout << res << endl; }