E - Payment Required Editorial by en_translator
Consider the following Dynamic Programming (DP): for \(T\subset \lbrace 1,2,\ldots,N\rbrace\) and \(0\le x\le X\), let \(d[T][x]\) be the maximum expected score when he has already solved the problems in \(T\) and has \(x\) yen left.
We consider the recurrence relations that \(d[T][x]\) satisfies.
If he submits problem \(i\) (\(i \notin T,\ x\geq C_i\)), he solves it with probability \(P_i\) percent and does not solve it \((100-P_i)\) percent, so the maximum expected score for this case is \(\displaystyle \frac{P_i}{100}\left(S_i+d[T\cup\lbrace i\rbrace][x - C_i] \right) + \frac{100-P_i}{100}d[T][x - C_i] \). Thus, it is sufficient to evaluate this expected value for all unsolved problems and let \(c[T][x]\) be the maximum value among them.
After filling the DP table, the answer can be found as \(\displaystyle d[\varnothing][X]\). The computational complexity is \(O(NX2^N)\).
N, X = map(int, input().split())
S = [0] * N
C = [0] * N
P = [0] * N
for i in range(N):
S[i], C[i], P[i] = map(int, input().split())
P[i] /= 100
d = [[0.0 for _ in range(X + 1)] for _ in range(1 << N)]
for x in range(X + 1):
for s in range(1 << N):
for i in range(N):
xx = x - C[i]
ss = s | (1 << i)
if xx < 0 or s == ss:
continue
val = P[i] * (d[ss][xx] + S[i]) + (1 - P[i]) * d[s][xx]
d[s][x] = max(d[s][x], val)
print(d[0][X])
posted:
last update: