結果

問題 No.90 品物の並び替え
ユーザー matsu7874matsu7874
提出日時 2015-10-27 14:06:40
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 16 ms / 5,000 ms
コード長 624 bytes
コンパイル時間 1,186 ms
コンパイル使用メモリ 148,348 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-11 04:21:57
合計ジャッジ時間 1,906 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

int main() {
  int N, M;

  scanf("%d %d", &N, &M);

  vector<vector<int> > score = vector<vector<int> >(9, vector<int>(9, 0));

  for (int i = 0; i < M; i++) {
    int a, b, c;
    scanf("%d %d %d", &a, &b, &c);
    score[a][b] = c;
  }
  long long int max_score = 0;
  int p[10];

  for (int i = 0; i < N; i++) {
    p[i] = i;
  }

  do {
    int s = 0;

    for (int i = 0; i < N - 1; i++)
      for (int j = i + 1; j < N; j++) s += score[p[i]][p[j]];
    if (s > max_score) max_score = s;
  } while (next_permutation(p, p + N));
  printf("%d\n", max_score);
  return 0;
}
0