問題一覧 > 通常問題

No.357 Rearranging Items (Middle)

レベル : / AI推定難易度 : 1350 / 実行時間制限 : 1ケース 5.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 215
作問者 : ciel
お気に入りにしたユーザー ProblemId : 810 / 自分の提出
問題文最終更新日: 2026-06-25 01:46:49
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Back to the original
yukicoder April Contest (順位表) の他の問題:

Problem Statement

There are items numbered 0 to (N-1).
There is also a score table whose rows are written in the format
item1 item2 score
.
This means that when the items are arranged, score points are obtained if item1 comes before item2.

Given the score table, you want to maximize the points obtained by rearranging the items appropriately. Output that score.

Input

N M
item1[1] item2[1] score[1]
…
item1[M] item2[M] score[M]

N: the number of items
M: the number of rows in the score table
item1[i] item2[i] score[i] (1<=i<=M): item 1, item 2, score

Constraints
2<=N<=14
1<=M<=N*(N-1)
0<=item1,item2<N
item1!=item2
1<=score<=10000

No two distinct rows of the score table have both the same item1 and the same item2.

Output

Output the maximum score that can be obtained. Print a newline after the output.

Sample

Sample 1
Input
4 9
0 1 1
0 2 2
0 3 3
1 2 4
1 3 5
2 3 6
3 2 100
2 1 100
1 0 100
Output
300

3 2 1 0
The maximum of 300 points is achieved when the items are arranged as above.

0 1 2 3
Note that when the items are arranged as above, 6 rows apply, but the score is 21 points, so the highest score is not obtained.

提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。