Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<stdio.h>
- #include<algorithm>
- #include<set>
- #include<map>
- #include<queue>
- #include<stack>
- #include<deque>
- #include<vector>
- #include<string>
- #include<math.h>
- using namespace std;
- #define INF 1000000000
- #define lint long long
- #define pb push_back
- #define mp make_pair
- #define MOD 1000000007
- lint a[1005][2006];
- long double d[1005][2005];
- long double p[1005][2005];
- int main()
- {
- int tc;
- scanf("%d",&tc);
- while(tc--)
- {
- int n,i,j;
- scanf("%d",&n);
- for(i=1;i<=n;++i)
- {
- for(j=1;j<=2*i;++j)
- {
- scanf("%lld",&a[i][j]);
- }
- }
- for(i=1;i<=n+1;++i)
- {
- for(j=1;j<=i;++j)
- {
- d[i][j]=0;
- p[i][j]=0;
- }
- }
- d[1][1]=0;
- p[1][1]=1;
- for(i=1;i<=n;++i)
- {
- for(j=1;j<=i;++j)
- {
- //cout<<i<<" x "<<j<<endl;
- //cout<<d[i][j]<<" "<<p[i][j]<<endl;
- int len1, len2;
- len1=a[i][2*j-1];
- len2=a[i][2*j];
- double p1;
- double p2;
- if(len1==len2)
- {
- p1=0.5;
- p2=0.5;
- }
- else if(len1<len2)
- {
- p1=1;
- p2=0;
- }
- else
- {
- p1=0;
- p2=1;
- }
- //cout <<p1<<" "<<p2<<endl;
- //cout<<len1<<" "<<len2<<endl;
- d[i+1][j]+=p1*(p[i][j]*len1+d[i][j]);
- d[i+1][j+1]+=p2*(p[i][j]*len2+d[i][j]);
- p[i+1][j]+=p1*p[i][j];
- p[i+1][j+1]+=p2*p[i][j];
- //cout<<i+1<<" "<<j<<" "<<d[i+1][j]<<" ";
- //cout<<i+1<<" "<<j+1<<" "<<d[i+1][j+1]<<endl;
- }
- }
- double ans=0;
- for(i=1;i<=n+1;++i)
- {
- ans+=d[n+1][i];
- //cout << d[n+1][i]<<" ";
- }
- printf("%.9lf\n",ans);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement