Sanath12345

Untitled

Jun 23rd, 2021
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.22 KB | None | 0 0
  1. //Problem link :
  2. //CREDITS : sanath kumar
  3. #include<bits/stdc++.h>
  4. using namespace std;
  5. #define ll long long int
  6. #define ld long double
  7. #define mod 1000000007
  8. #define inf 1e9
  9. #define endl "\n"
  10. #define pb push_back
  11. #define vi vector<ll>
  12. #define vs vector<string>
  13. #define pii pair<ll,ll>
  14. #define ump unordered_map
  15. #define mp make_pair
  16. #define pq_max priority_queue<ll>
  17. #define pq_min priority_queue<ll,vector<ll>,greater<ll>>
  18. #define all(v) v.begin(),v.end()
  19. #define ff first
  20. #define ss second
  21. #define mid(l,r) (l+(r-l))/2
  22. #define bitc(x) __builtin_popcount(x)
  23. #define read(a,n) for(int i=1;i<=n;i++) cin>>a[i];
  24. #define print_(a,x,y) {for(int i=x;i<=y;i++) cout<<a[i]<<" ";cout<<endl;}
  25. #define loop(i,a,b) for(int i=(a);i<=(b);i++)
  26. #define looprev(i,a,b) for(int i=(a);i>=(b);i--)
  27. #define iter(c,it) for(__typeof(c.begin()) it=c.begin();it!=c.end();it++)
  28. #define boost ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
  29. #define log(args...) {string _s=#args;replace(_s.begin(),_s.end(),',',' ');stringstream _ss(_s);istream_iterator<string> _it(_ss);err(_it,args);}
  30. #define logarr(arr,a,b) for(int z=(a);z<=(b);z++) cout<<(arr[z])<<" ";cout<<endl;
  31. template<typename T> T gcd(T a,T b) {if(b==0) return a; return gcd(b,a%b);}
  32. template<typename T> T lcm(T a,T b) {return a*(b/gcd(a,b));}
  33. ll add(ll a,ll b) {return ((a%mod)+(b%mod))%mod;}
  34. ll sub(ll a,ll b) {return ((a%mod)-(b%mod)+mod)%mod;}
  35. ll mul(ll a,ll b) {return ((a%mod)*(b%mod))%mod;}
  36.  
  37. void err(istream_iterator<string> it){}
  38. template<typename T,typename... Args>
  39. void err(istream_iterator<string> it,T a,Args... args){
  40. cout<<*it<<" = "<<a<<endl;
  41. err(++it,args...);
  42. }
  43. ll *getfactorial(){
  44. int m=1e6;
  45. ll *fact=new ll[m+1];
  46. fact[0]=1;
  47. loop(i,1,m){
  48. fact[i]=(fact[i-1]*i)%mod;
  49. }
  50. // time complexity O(n)
  51. return fact;
  52. }
  53. vi *getfactors(){
  54. int n=2e5;
  55. vi *factors=new vi[n+5];
  56. loop(i,1,n){
  57. for(int j=i;j<=n;j+=i){
  58. factors[j].pb(i);
  59. }
  60. }
  61. // time complexity O(nlogn)
  62. return factors;
  63. }
  64. ll power(ll a,ll b,ll m=mod){
  65. if(b==0) return 1;
  66. ll smallans=power(a,b/2,m);
  67. ll ans=(smallans*smallans)%m;
  68. if(b%2==1){
  69. ans=(ans*a)%m;
  70. }
  71. return ans;
  72. // time complexity O(logb)
  73. }
  74. bool *isprime(){
  75. int m=1e6;
  76. bool *p=new bool[m+5];
  77. loop(i,0,m) p[i]=true;
  78. p[0]=false;
  79. p[1]=false;
  80. loop(i,2,sqrt(m)){
  81. for(int j=2*i;j<=m;j+=i){
  82. p[j]=false;
  83. }
  84. }
  85. // time complexity O(nlogn)
  86. return p;
  87. }
  88. ll nCr(ll n,ll r,int m=mod){
  89. if(n<r) return 0;
  90. ll *fac=getfactorial();
  91. ll ans=fac[n];
  92. ans=(ans*power(fac[n-r],m-2))%m;
  93. ans=(ans*power(fac[r],m-2))%m;
  94. return ans;
  95. }
  96.  
  97. //==================START==================
  98. vi a(1005);
  99. ll dp[1005][1005];
  100. ll solve(int i,int j){
  101. if(i>j) return 0;
  102. if(dp[i][j]!=-1) return dp[i][j];
  103. if(i==j) return dp[i][j]=a[i];
  104. if(i+1==j) return dp[i][j]=a[i]+a[j];
  105. return dp[i][j]=2*a[i]+2*a[j]+solve(i+2,j)+2*solve(i+1,j-1)+solve(i,j-2);
  106. }
  107. int main(){
  108. boost
  109. int t;
  110. cin>>t;
  111. cout<<fixed<<setprecision(15)<<endl;
  112. while(t--){
  113. int n;
  114. cin>>n;
  115. read(a,n);
  116. memset(dp,-1,sizeof(dp));
  117. ld ans=(ld)solve(1,n);
  118. loop(i,1,n-1){
  119. ans=((ld)ans/2);
  120. }
  121. cout<<ans<<endl;
  122. }
  123. }
Advertisement
Add Comment
Please, Sign In to add comment