結果

問題 No.58 イカサマなサイコロ
ユーザー lapilapi
提出日時 2019-03-27 22:49:47
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 1,494 bytes
コンパイル時間 990 ms
コンパイル使用メモリ 105,096 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-01 14:33:55
合計ジャッジ時間 1,747 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <numeric>
#include <regex>
#include <tuple>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
#define MOD 1000000007 // 10^9 + 7
#define INF 1000000000 // 10^9
#define LLINF 1LL<<60

double dp1[11][61]; // dp1[i][j] : サイコロをi回投げて合計がjになる確率
double dp2[11][61];


int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	int N, K; cin >> N >> K;

	for (int i = 0; i < N; i++) {
		for (int j = 0; j <= 60; j++) {
			dp1[i][j] = 0;
			dp2[i][j] = 0;
		}
	}

	dp1[0][0] = 1;
	dp2[0][0] = 1;
	for (int i = 0; i < N; i++) {
		for (int j = 0; j <= 60; j++) {
			if (i <= K - 1) {
				if (dp1[i][j]) {
					for (int k = 4; k <= 6 && j + k <= 60; k++) dp1[i + 1][j + k] += (dp1[i][j] / 3);
				}
			}
			else {
				if (dp1[i][j]) {
					for (int k = 1; k <= 6 && j + k <= 60; k++) dp1[i + 1][j + k] += (dp1[i][j] / 6);
				}
			}
			if (dp2[i][j]) {
				for (int k = 1; k <= 6 && j + k <= 60; k++) dp2[i + 1][j + k] += (dp2[i][j] / 6);
			}
		}
	}

	vector<double> V;
	V.push_back(0); // V[i] : 次郎君のN個の和がi以下になる確率
	for (int i = 1; i <= 60; i++) V.push_back(V[i - 1] + dp2[N][i]);

	double ans = 0;
	for (int i = 1; i <= 60; i++) {
		ans += dp1[N][i] * V[i - 1];
	}

	cout << ans << endl;
	// for (int i = 0; i <= 60; i++) cout << V[i] << " ";

	return 0;
}
0