题解:
看到了树
很明显就是树形dp吗
然后随便yy一下方程就好了
代码:
#include<bits/stdc++.h> using namespace std; int n,j; double a[100],s,k1,c,f1[100],f[100][100][100]; int main() { cin>>n>>k1>>c; for (int i=1;i<=n;i++) { cin>>a[i]; s+=a[i]; } for (int i=1;i<=n;i++) f1[i]=a[i]/s; for (int i=1;i<=n;i++) for (int j=1;j<=n;j++) for (int x=0;x<=n-1;x++)f[i][j][x]=210000000; for (int i=1;i<=n+1;i++) for (int x=0;x<=n-1;x++)f[i][i][x]=(k1*(x+1)+c)*f1[i]; for (int i=1;i<=n+1;i++) for (int x=0;x<=n;x++)f[i][i-1][x]=0; for (int len=2;len<=n;len++) for (int i=1;i<=n-len+1;i++) { int j=i+len-1; for (int x=0;x<=n-1;x++) for (int k=i;k<=j;k++) f[i][j][x]=min(f[i][j][x],f[i][k-1][x+1]+f[k+1][j][x+1]+(k1*(x+1)+c)*f1[k]); } printf("%.3f",f[1][n][0]); return 0; }