結果

問題 No.90 品物の並び替え
ユーザー alpha_virginisalpha_virginis
提出日時 2016-08-09 14:49:49
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 21 ms / 5,000 ms
コード長 1,185 bytes
コンパイル時間 1,906 ms
コンパイル使用メモリ 162,812 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-24 23:03:27
合計ジャッジ時間 2,525 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>

template<typename T> T in() { abort(); return T(); }
template<> std::string in() { std::string str; std::cin >> str; return str; }
template<> int in() { int x; scanf("%d", &x); return x; }

template<typename T> void out(T x) { abort(); }
template<> void out(const char* x) { printf("%s\n", x); }
template<> void out(std::string x) { std::cout << x << std::endl; }
template<> void out(int x) { printf("%d\n", x); }
template<> void out(long x) { printf("%ld\n", x); }

int score[10][10];
int n, m;

int dfs(int i, int xs[10], bool check[10], int w) {
  if( i == n ) {
    return w;
  }
  int max = 0;
  for(int j = 0; j < n; ++j) {
    if( check[j] ) continue;
    int w2 = w;
    for(int k = 0; k < i; ++k) {
      w2 += score[xs[k]][j];
    }
    xs[i] = j;
    check[j] = true;
    max = std::max(max, dfs(i + 1, xs, check, w2));
    check[j] = false;
    xs[i] = -1;
  }
  return max;
}

int main() {
  n = in<int>();
  m = in<int>();
  for(int i = 0; i < m; ++i) {
    int a, b, c;
    a = in<int>();
    b = in<int>();
    c = in<int>();
    score[a][b] = c;
  }

  int xs[10] = {};
  bool check[10] = {};

  out( dfs(0, xs, check, 0) );
  
  return 0;
}
0