結果

問題 No.845 最長の切符
ユーザー i_mrhji_mrhj
提出日時 2019-08-08 16:55:45
言語 C
(gcc 12.3.0)
結果
TLE  
実行時間 -
コード長 1,077 bytes
コンパイル時間 164 ms
コンパイル使用メモリ 30,228 KB
実行使用メモリ 8,760 KB
最終ジャッジ日時 2023-09-26 00:38:51
合計ジャッジ時間 8,117 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,972 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 3 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 2,966 ms
4,376 KB
testcase_11 AC 20 ms
4,376 KB
testcase_12 AC 55 ms
4,376 KB
testcase_13 AC 3 ms
4,376 KB
testcase_14 AC 4 ms
4,376 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[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] = Max(d[a][b], c);
    d[b][a] = Max(d[b][a], c);
    cnt[a]++; cnt[b]++;
  }

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

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

  return 0;
}
0