Advertisement
Saleh127

Light OJ 1030

Aug 2nd, 2021
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.87 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long
  4. #define test int tt; cin>>tt; for(int cs=1;cs<=tt;cs++)
  5.  
  6. double a[200],dp[200];
  7. ll n;
  8.  
  9. double sol(ll pos)
  10. {
  11. if(pos==n) return a[n];
  12.  
  13. if(dp[pos]!=-1) return dp[pos];
  14.  
  15. double x=0;
  16.  
  17. for(ll i=1;i<=6;i++)
  18. {
  19. if(pos+i<=n)
  20. {
  21. ll y=min(6ll,n-pos);
  22.  
  23. x+=(1.00/y)*sol(pos+i);
  24. }
  25. }
  26.  
  27. dp[pos]=a[pos]+x;
  28.  
  29. return dp[pos];
  30. }
  31.  
  32. int main()
  33. {
  34. ios_base::sync_with_stdio(0);
  35. cin.tie(0);cout.tie(0);
  36.  
  37. test
  38. {
  39. cin>>n;
  40.  
  41. ll i,j,k,l;
  42.  
  43. for(i=1;i<=n;i++)
  44. {
  45. cin>>a[i];
  46. }
  47.  
  48. for(i=0;i<=n+4;i++)
  49. {
  50. dp[i]=-1;
  51. }
  52.  
  53. cout<<"Case "<<cs<<": "<<fixed<<setprecision(9)<<sol(1ll)<<endl;
  54. }
  55.  
  56.  
  57. return 0;
  58. }
  59.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement