Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define ll long long
- #include <bits/stdc++.h>
- using namespace std;
- const int OO = 1e9;
- const double EPS = 1e-9;
- int n,m,k;
- double qe(double b, int p) {
- if(p == 0) {
- return 1.0;
- }
- if(p & 1) {
- return b*qe(b,p-1);
- }
- double ret = qe(b,p/2);
- return ret*ret;
- }
- double mem[1001];
- double p[1001];
- double solve(int x) {
- if(x == 0) {
- return 0;
- }
- if(mem[x] != -1) {
- return mem[x];
- }
- double &ret = mem[x];
- ret = p[0];
- for(int i = 1; i < n; i++) {
- ret += p[i]*qe(solve(x-1),i);
- }
- return ret;
- }
- int main()
- {
- ios_base::sync_with_stdio(false);
- cin.tie(NULL);
- cout.tie(NULL);
- int t;
- cin >> t;
- cout.precision(7);
- cout << fixed;
- for(int ti = 1; ti <= t; ti++) {
- cin >> n >> k >> m;
- for(int i = 0; i < n; i++) {
- cin >> p[i];
- }
- for(int i = 0; i <= m; i++) {
- mem[i] = -1;
- }
- double ans;
- if(k == 0) {
- ans = 1.0;
- }
- else if(m == 0) {
- ans = 0.0;
- }
- else {
- ans = qe(solve(m),k);
- }
- cout << "Case #" << ti << ": " << ans << "\n";
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement