結果

問題 No.134 走れ!サブロー君
ユーザー tottoripapertottoripaper
提出日時 2015-03-16 05:12:23
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 7 ms / 5,000 ms
コード長 1,117 bytes
コンパイル時間 274 ms
コンパイル使用メモリ 36,324 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-22 18:03:14
合計ジャッジ時間 933 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 1 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 4 ms
5,376 KB
testcase_08 AC 7 ms
5,376 KB
testcase_09 AC 7 ms
5,376 KB
testcase_10 AC 0 ms
5,376 KB
testcase_11 AC 1 ms
5,376 KB
testcase_12 AC 0 ms
5,376 KB
testcase_13 AC 0 ms
5,376 KB
testcase_14 AC 1 ms
5,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:29:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   29 |     scanf("%lf %lf", &X[0], &Y[0]);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
main.cpp:31:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   31 |     scanf("%d", &N);
      |     ~~~~~^~~~~~~~~~
main.cpp:40:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   40 |         scanf("%lf %lf %lf", X+i, Y+i, W+i);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

ソースコード

diff #

#include <cstdio>
#include <algorithm>

double dp[1<<13][14], weight[1<<13];
double X[14], Y[14], W[14];
int N;

double dist(int i, int j){
    return std::abs(X[i] - X[j]) + std::abs(Y[i] - Y[j]);
}

double rec(int state, int index){
    if(state == 0){
        return 100.0 / 120 * dist(0, index);
    }
    if(dp[state][index] > 0.0){return dp[state][index];}

    double res = 1e20;
    for(int i=0;i<N;i++){
        if(!(state >> i & 1)){continue;}

        res = std::min(res, (weight[state] + 100) / 120 * dist(index, i+1) + W[i+1] + rec(state & ~(1 << i), i+1));
    }

    return dp[state][index] = res;
}

int main(){
    scanf("%lf %lf", &X[0], &Y[0]);
    
    scanf("%d", &N);
    
    for(int i=0;i<1<<N;i++){
        for(int j=0;j<=N;j++){
            dp[i][j] = -1.0;
        }
    }

    for(int i=1;i<=N;i++){
        scanf("%lf %lf %lf", X+i, Y+i, W+i);
    }

    for(int i=0;i<1<<N;i++){
        double sum = 0.0;
        for(int j=0;j<N;j++){
            if(!(i >> j & 1)){continue;}
            sum += W[j+1];
        }
        weight[i] = sum;
    }

    printf("%.6f\n", rec((1<<N)-1, 0));
}
0