結果

問題 No.90 品物の並び替え
ユーザー otsnskotsnsk
提出日時 2014-12-17 18:59:13
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 21 ms / 5,000 ms
コード長 785 bytes
コンパイル時間 2,019 ms
コンパイル使用メモリ 58,732 KB
実行使用メモリ 4,372 KB
最終ジャッジ日時 2023-09-02 18:33:35
合計ジャッジ時間 1,417 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,372 KB
testcase_01 AC 3 ms
4,372 KB
testcase_02 AC 1 ms
4,372 KB
testcase_03 AC 2 ms
4,368 KB
testcase_04 AC 2 ms
4,372 KB
testcase_05 AC 3 ms
4,372 KB
testcase_06 AC 4 ms
4,372 KB
testcase_07 AC 2 ms
4,372 KB
testcase_08 AC 2 ms
4,372 KB
testcase_09 AC 21 ms
4,368 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int score[10][10];

int main() {
    int N, M, i1, i2, s;
    int row[10];
    int total, max_total;

    cin >> N >> M;
    for (int i = 0; i < M; i++) {
        cin >> i1 >> i2 >> s;
        score[i1][i2] = s;
    }
    for (int i = 0; i < N; i++) {
        row[i] = i;
    }
    max_total = 0;
    do {
        // for (int i = 0; i < N; i++) cout << row[i]; cout << "\n";
        total = 0;
        for (int i = 0; i < N-1; i++) {
            for (int j = i; j < N; j++) {
                total += score[row[i]][row[j]];
            }
        }
        max_total = max(max_total, total);
    }
    while (next_permutation(row, row+N));

    cout << max_total << endl;

    return 0;
}
0