-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathp121.cpp
More file actions
35 lines (31 loc) · 702 Bytes
/
Copy pathp121.cpp
File metadata and controls
35 lines (31 loc) · 702 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
// See p121.tex for solution.
#include <algorithm>
#include <iostream>
#include "euler.h"
BEGIN_PROBLEM(121, solve_problem_121)
PROBLEM_TITLE("Investigate the game of chance involving colored discs")
PROBLEM_ANSWER("2269")
PROBLEM_DIFFICULTY(1)
PROBLEM_FUN_LEVEL(1)
PROBLEM_TIME_COMPLEXITY("N^2")
PROBLEM_SPACE_COMPLEXITY("N")
END_PROBLEM()
static void solve_problem_121()
{
#if 0
const int N = 4;
#else
const int N = 15;
#endif
const int M = N/2+1;
double P[M+1] = {0};
P[0] = 1;
for (int n = 1; n <= N; n++)
{
for (int m = std::min(n, M); m >= 1; m--)
{
P[m] = P[m-1]/(n+1) + P[m]*n/(n+1);
}
}
std::cout << static_cast<int>(1/P[M]) << std::endl;
}