結果

問題 No.845 最長の切符
ユーザー tarattata1tarattata1
提出日時 2019-06-29 14:11:14
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,710 bytes
コンパイル時間 680 ms
コンパイル使用メモリ 74,264 KB
実行使用メモリ 11,204 KB
最終ジャッジ日時 2023-09-14 23:12:35
合計ジャッジ時間 2,086 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,384 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 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,380 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 20 ms
11,076 KB
testcase_27 AC 1 ms
4,376 KB
testcase_28 AC 20 ms
11,136 KB
testcase_29 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <list>
#include <iterator>
#include <assert.h>
#pragma warning(disable:4996) 

typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;
using namespace std;

ll dp[1<<16][16];

int main(int argc, char* argv[])
{
    int n,m;
    scanf("%d%d", &n, &m);

    int g[16][16]={0};
    int i,j;
    for(i=0; i<16; i++) {
        for(j=0; j<16; j++) {
            g[i][j]=INF;
        }
    }
    for(i=0; i<m; i++) {
        int a,b,c;
        scanf("%d%d%d", &a, &b, &c);
        g[a-1][b-1]=c;
        g[b-1][a-1]=c;
    }

    int k;
    for(i=0; i<(1<<n); i++) {
        for(k=0; k<n; k++) {
            dp[i][k] = -1;
        }
    }

    for(i=1; i<(1<<n); i++) {
        for(k=0; k<n; k++) {
            if(i & (1<<k)) {
                int prev = (i & ~(1<<k));
                if(prev==0) {
                    dp[i][k] = 0;
                }
                else {
                    int j;
                    for(j=0; j<n; j++) {
                        if(dp[prev][j]>=0 && g[j][k]!=INF) {
                            dp[i][k] = MAX(dp[i][k], dp[prev][j] + g[j][k]);
                        }
                    }
                }
            }
        }
    }
    ll ans=0;
    for(i=1; i<(1<<n); i++) {
        for(k=0; k<n; k++) {
            if(dp[i][k]>=0) {
                ans = MAX(ans, dp[i][k]);
            }
        }
    }
    printf("%lld\n", ans);

    return 0;
}
0