結果

問題 No.845 最長の切符
ユーザー i_mrhji_mrhj
提出日時 2019-08-08 16:50:03
言語 C
(gcc 12.3.0)
結果
WA  
実行時間 -
コード長 1,080 bytes
コンパイル時間 235 ms
コンパイル使用メモリ 30,100 KB
実行使用メモリ 4,504 KB
最終ジャッジ日時 2023-09-26 00:38:03
合計ジャッジ時間 2,182 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

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[16][1 << MAX_N][16];
int n, d[16][16];

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

  int r = 0;
  for (int i = 0; i < n; i++) {
    if (!(s >> i & 1) && d[v][i] != 0) {
      r = Max(r, rec(a, 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;
  int cnt[16] = {};
  for (int i = 0; i < m; i++) {
    scanf("%d %d %d", &a, &b, &c);
    a--; b--;
    d[a][b] = c;
    d[b][a] = c;
    cnt[a]++; cnt[b]++;
  }

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

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

  return 0;
}
0