ZOJ-3640-Help me escape
Http://acm.zju.edu.cn/onlinejudge/showProblem.do? Problemcode = 3640.
A vampire has n routes for him. Each time he takes a random route, each route has a limit. If the attack power of this vampire is greater than or equal to a certain value, it will take t days to escape. Otherwise, it will take 1 day and increase the attack power and ask him what he expects to escape.
# Include <iostream >#include <cstdio >#include <cstring >#include <cstdlib> # include <cmath> using namespace STD; int C [105]; int T [105]; int V [20010]; double F [20010]; int N; double Sol (INT at) {int I; If (V [at]) return f [at]; V [at] = 1; F [at] = 0; for (I = 1; I <= N; I ++) if (at> C [I]) f [at] + = T [I]; elsef [at] + = Sol (at + C [I]) + 1; f [at]/= N; return f [at];} int main () {int I, ff; while (scanf ("% d", & N, & ff )! = EOF) {for (I = 1; I <= N; I ++) scanf ("% d", & C [I]); for (I = 1; I <= N; I ++) T [I] = (INT) (1 + SQRT (5.0) * 0.5 * C [I] * C [I]); memset (v, 0, sizeof (v); printf ("%. 3lf \ n ", Sol (ff);} return 0 ;}