結果

問題 No.845 最長の切符
ユーザー i_mrhji_mrhj
提出日時 2019-08-08 17:14:46
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 67 ms / 3,000 ms
コード長 1,032 bytes
コンパイル時間 232 ms
コンパイル使用メモリ 30,112 KB
実行使用メモリ 5,932 KB
最終ジャッジ日時 2023-09-26 01:11:22
合計ジャッジ時間 1,947 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 0 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 0 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 0 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 0 ms
4,380 KB
testcase_14 AC 1 ms
4,380 KB
testcase_15 AC 13 ms
4,380 KB
testcase_16 AC 53 ms
5,932 KB
testcase_17 AC 11 ms
4,380 KB
testcase_18 AC 25 ms
4,376 KB
testcase_19 AC 6 ms
4,376 KB
testcase_20 AC 60 ms
5,900 KB
testcase_21 AC 67 ms
5,816 KB
testcase_22 AC 11 ms
4,376 KB
testcase_23 AC 3 ms
4,376 KB
testcase_24 AC 52 ms
5,816 KB
testcase_25 AC 1 ms
4,376 KB
testcase_26 AC 1 ms
4,376 KB
testcase_27 AC 0 ms
4,376 KB
testcase_28 AC 1 ms
4,380 KB
testcase_29 AC 0 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

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 dp[s][v] = 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