結果

問題 No.560 ふしぎなナップサック
ユーザー @abcde@abcde
提出日時 2019-05-31 22:51:23
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,193 bytes
コンパイル時間 1,841 ms
コンパイル使用メモリ 167,788 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-17 22:38:42
合計ジャッジ時間 2,772 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 2 ms
4,348 KB
testcase_12 AC 2 ms
4,348 KB
testcase_13 AC 2 ms
4,348 KB
testcase_14 AC 2 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using LL = long long;

double dp[1001][3]; // M × 2, M + 1, 0 のパターンを, それぞれ保管.

int main() {
    
    // 1. 入力情報取得.
    LL M, N;
    cin >> M >> N;

    // 2. 最初にM 円入っているナップサックを, ちょうど N 回叩いたときの
    // ナップサックの中身の金額の期待値を計算.
    dp[0][0] = dp[0][1] = dp[0][2] = M;
    for(int i = 1; i <= N; i++){
        // 中身が, 2倍の金額になるケース.
        dp[i][0] = (dp[i - 1][0] + dp[i - 1][1] + dp[i - 1][2]) * 2 / 3.0;
        
        // 中身が, +1円増加するケース.
        dp[i][1] = (dp[i - 1][0] + dp[i - 1][1] + dp[i - 1][2] + 3) / 3.0;

        // 中身が, 0円になるケース.
        dp[i][2] = (dp[i - 1][0] + dp[i - 1][1] + dp[i - 1][2]) * 0 / 3.0;

    }
    
    // for(int i = 1; i <= N; i++){
    //     for(int j = 0; j < 3; j++){
    //         cout << dp[i][j] << " ";
    //     }
    //     cout << endl;
    // }
    
    // 3. 出力.
    double ans = (dp[N][0] + dp[N][1] + dp[N][2]) / 3.0;
    cout << fixed;
    cout << setprecision(10) << ans << endl;
    return 0;
    
}
0