結果

問題 No.75 回数の期待値の問題
ユーザー imulanimulan
提出日時 2016-07-08 00:28:49
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 18 ms / 5,000 ms
コード長 838 bytes
コンパイル時間 1,375 ms
コンパイル使用メモリ 162,184 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-21 01:02:09
合計ジャッジ時間 2,208 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

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

typedef long long ll;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define each(itr,c) for(__typeof(c.begin()) itr=c.begin(); itr!=c.end(); ++itr)
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define fi first
#define se second

const int N=10000;

int main()
{
    int k;
    cin >>k;

    double ans=0;
    double dp[201]={0};
    dp[0]=1;

    for(int i=1; i<N; ++i)
    {
        double newdp[201]={0};
        rep(j,k)
        {
            for(int x=1; x<=6; ++x)
            {
                if(j+x<=k) newdp[j+x]+=dp[j]/6;
                else newdp[0]+=dp[j]/6;
            }
        }
        ans+=i*newdp[k];
        //printf("%d : %lf\n", i,newdp[k]);
        rep(j,k+1) dp[j]=newdp[j];
    }

    printf("%.10lf\n", ans);
    return 0;
}
0