結果

問題 No.845 最長の切符
ユーザー i_mrhji_mrhj
提出日時 2019-08-08 17:02:46
言語 C
(gcc 12.3.0)
結果
TLE  
実行時間 -
コード長 1,019 bytes
コンパイル時間 589 ms
コンパイル使用メモリ 29,612 KB
実行使用メモリ 5,968 KB
最終ジャッジ日時 2023-09-26 01:07:35
合計ジャッジ時間 8,571 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,968 KB
testcase_01 AC 0 ms
4,388 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 0 ms
4,504 KB
testcase_04 AC 0 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 3 ms
4,384 KB
testcase_09 AC 1 ms
4,384 KB
testcase_10 AC 2,600 ms
4,380 KB
testcase_11 AC 17 ms
4,384 KB
testcase_12 AC 49 ms
4,380 KB
testcase_13 AC 3 ms
4,384 KB
testcase_14 AC 4 ms
4,380 KB
testcase_15 TLE -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
#include <math.h>
#include <limits.h>
#define Max(a, b) ((a) > (b) ? (a) : (b))
#define Min(a, b) ((a) > (b) ? (b) : (a))
#define abs(x) ((x) > 0 ? (x) : -(x))
#define rep(i, n) for(int i = 0; i < (n); i++)
#define MOD 1000000007 //10^9 + 7
#define endl printf("\n")
typedef long long ll;
#define MAX_N 16

int dp[1 << MAX_N][MAX_N];
int n, d[MAX_N][MAX_N];

int
rec(int s, int v)
{
  if (dp[s][v] > 0) return dp[s][v];

  int r = 0;
  for (int i = 0; i < n; i++) {
    if (!(s >> i & 1) && d[v][i] != 0) {
      r = Max(r, rec(s | 1 << i, i) + d[v][i]);
    }
  }

  return r;
}

int
main(int argc, char **argv)
{
  int m;
  scanf("%d %d", &n, &m);
  int a, b, c;
  for (int i = 0; i < m; i++) {
    scanf("%d %d %d", &a, &b, &c);
    a--; b--;
    d[a][b] = Max(d[a][b], c);
    d[b][a] = Max(d[b][a], c);
  }

  int ans = 0;
  for (int i = 0; i < n; i++) {
    ans = Max(ans, rec(1 << i, i));
  }

  printf("%d\n", ans);

  return 0;
}
0