Advertisement
Um_nik

Untitled

Jul 18th, 2014
274
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.15 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdio>
  3. #include <cstdlib>
  4. #include <cmath>
  5. using namespace std;
  6. typedef long long ll;
  7.  
  8. int n;
  9. ll now;
  10. ll cost;
  11. double w[100][100];
  12. double p[100];
  13. double ans;
  14.  
  15. int main()
  16. {
  17.     freopen("tvshow.in", "r", stdin);
  18.     freopen("tvshow.out", "w", stdout);
  19.  
  20.     scanf("%d%I64d\n", &n, &cost);
  21.     for (int i = 0; i < n; i++)
  22.     {
  23.         scanf("%lf", &p[i]);
  24.         p[i] /= 100.;
  25.     }
  26.     for (int i = 0; i < n; i++)
  27.     {
  28.         w[i][i] = 1.;
  29.         for (int j = i + 1; j <= n; j++)
  30.             w[i][j] = w[i][j - 1] * p[j - 1];
  31.     }
  32.     ans = 100.;
  33.     for (int i = 1; i <= n; i++)
  34.         ans = max(ans, w[0][i] * (double)(100LL << (ll)i));
  35.     now = 50LL;
  36.  
  37.     for (int i = 0; i < n; i++)
  38.     {
  39.         now = now << 1LL;
  40.         if (now <= cost)
  41.             continue;
  42.         ll tmp_now = now - cost;
  43.         double r = w[0][i] * (double)tmp_now;
  44.         double tans = 0.;
  45.         for (int j = i; j <= n; j++)
  46.         {
  47.             double rr = r * (1. - p[j]);
  48.             double tt = 0.;
  49.             for (int k = j + 1; k <= n; k++)
  50.             {
  51.                 tt = max(rr, tt);
  52.                 if (k < n)
  53.                     rr = rr * p[k] * 2.;
  54.             }
  55.             tans += tt;
  56.             if (j < n)
  57.                 r = r * p[j] * 2.;
  58.         }
  59.         tans += r;
  60.         ans = max(ans, tans);
  61.     }
  62.  
  63.     printf("%.10lf\n", ans);
  64.     return 0;
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement