bzoj4318: OSU!
OKOK我比较傻。。一开始写了个n方的DP还调不出来。
实际上正推(因为这里正推逆推没有影响)
去分别求若询问x,x^2,x^3的答案,每增加一位相当于x+1
用x推出x^2:(x+1)^2=x^2+2x+1
用x和x^2推出x^3:(x+1)^3=x^3+3x^2+3x+1
没了。
#include<cstdio> #include<iostream> #include<cstring> #include<cstdlib> #include<algorithm> #include<cmath> using namespace std; double a[110000],f1[110000],f2[110000],f3[110000]; int main() { int n; scanf("%d",&n); for(int i=1;i<=n;i++) { scanf("%lf",&a[i]); f1[i]=(f1[i-1]+1)*a[i]; f2[i]=(f2[i-1]+2*f1[i-1]+1)*a[i]; f3[i]=f3[i-1]+(3*f2[i-1]+3*f1[i-1]+1)*a[i]; } printf("%.1lf\n",f3[n]); return 0; }
pain and happy in the cruel world.