Advertisement
_rashed

UVA 11021

Jun 28th, 2022
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.26 KB | None | 0 0
  1. #define ll long long
  2. #include <bits/stdc++.h>
  3. using namespace std;
  4.  
  5. const int OO = 1e9;
  6. const double EPS = 1e-9;
  7.  
  8. int n,m,k;
  9.  
  10. double qe(double b, int p) {
  11.     if(p == 0) {
  12.         return 1.0;
  13.     }
  14.     if(p & 1) {
  15.         return b*qe(b,p-1);
  16.     }
  17.     double ret = qe(b,p/2);
  18.     return ret*ret;
  19. }
  20.  
  21. double mem[1001];
  22. double p[1001];
  23.  
  24. double solve(int x) {
  25.     if(x == 0) {
  26.         return 0;
  27.     }
  28.     if(mem[x] != -1) {
  29.         return mem[x];
  30.     }
  31.     double &ret = mem[x];
  32.     ret = p[0];
  33.     for(int i = 1; i < n; i++) {
  34.         ret += p[i]*qe(solve(x-1),i);
  35.     }
  36.     return ret;
  37. }
  38.  
  39. int main()
  40. {
  41.     ios_base::sync_with_stdio(false);
  42.     cin.tie(NULL);
  43.     cout.tie(NULL);
  44.     int t;
  45.     cin >> t;
  46.     cout.precision(7);
  47.     cout << fixed;
  48.     for(int ti = 1; ti <= t; ti++) {
  49.         cin >> n >> k >> m;
  50.         for(int i = 0; i < n; i++) {
  51.             cin >> p[i];
  52.         }
  53.         for(int i = 0; i <= m; i++) {
  54.             mem[i] = -1;
  55.         }
  56.         double ans;
  57.         if(k == 0) {
  58.             ans = 1.0;
  59.         }
  60.         else if(m == 0) {
  61.             ans = 0.0;
  62.         }
  63.         else {
  64.             ans = qe(solve(m),k);
  65.         }
  66.         cout << "Case #" << ti << ": " << ans << "\n";
  67.     }
  68.     return 0;
  69. }
  70.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement