The first eye thought it was stupid. Slope optimization >_<
F[i] Indicates the maximum number of characters that can be output by the I-times ... f[i]=max{f[i-1]+1, (i-j-1) *f[j]},j<i-2
The result n in 100+ of time, loved to explode Longlong
According to the online puzzle can get (T_T). This question is about FFT optimization? (Follow CCZ to brush the problem is high-risk tat
The solution, however, is to find out the first few items of F, making x=n%5+15, the final answer f[n]=f[x]*4^ ((n-x)/5) ....
I didn't see it coming.
I'm obviously not even an FFT idiot. Had to write a pressure-level high-precision fast power. The result ran. 233
Suddenly it is clear that the solution is not FFT = =. In addition the status of a bunch of strange language is also moving >_<
1#include <cstdio>2#include <iostream>3#include <cstring>4 #definell Long Long5 #defineD Double6 using namespacestd;7 Const intmaxn=1002333;8 Const intModd=1000000000;9ll f[233];Ten intDl[maxn],l,r; Onell a[32333],c[32333],b[32333]; A intI,j,k,n,m,lena,lenc; - -Inline D XL (intKintj) {//k<j<i-2 the return(F[j]* (j+1)-f[k]* (k +1))/(d) (f[j]-f[k]); - } - intRA,FH;CharRx; -InlineintRead () { +Rx=getchar (), ra=0, fh=1; - while((rx<'0'|| Rx>'9') &&rx!='-') rx=GetChar (); + if(rx=='-') fh=-1, rx=GetChar (); A while(rx>='0'&&rx<='9') ra*=Ten, ra+=rx- -, Rx=getchar ();returnra*fh; at } -InlinevoidMultoa () { -Registerinti,j,k; -memset (b,0, (lena*2+1) <<3); - for(i=1; i<=lena;i++) for(j=1, k=i;j<=lena;j++,k++){ -b[k]+=a[i]*A[j]; in if(b[k]>=modd) b[k+1]+=b[k]/modd,b[k]%=modd; - } to for(k=lena<<1;! b[k];k--); +memcpy (A, B, (k +1) <<3); lena=K; - } theInlinevoidMultoc () { *Registerinti,j,k; $memset (b,0, (lena+lenc+1) <<3);Panax Notoginseng for(i=1; i<=lena;i++) for(j=1, k=i;j<=lenc;j++,k++){ -b[k]+=a[i]*C[j]; the if(b[k]>=modd) b[k+1]+=b[k]/modd,b[k]%=modd; + } A for(k=lena+lenc;! b[k];k--); thememcpy (C,b, (k +1) <<3); lenc=K; + } -InlinevoidPoiintb) {//Calculate 4^b $C[lenc=1]=1; a[lena=1]=4; $ while(b) { - if(b&1) Multoc (); -b>>=1; the if(b) Multoa (); - }Wuyi } the - intMain () { Wun=read (); -f[1]=1, f[2]=2, f[3]=3; AboutL=1, r=0; $ for(i=4; i<= -; i++){ - while(L<R&&XL (dl[r-1],dl[r]) >=XL (dl[r],i-3)) r--; -dl[++r]=i-3; - while(L<R&&I>XL (dl[l],dl[l+1])) l++; Af[i]=f[dl[l]]* (i-dl[l]-1); + if(f[i-1]+1>f[i]) f[i]=f[i-1]+1; the //printf ("i:%d%lld\n", I,f[i]); - } $ if(n<= -) printf ("%lld\n", F[n]);Else{ the intx=n%5+ the; thePoi ((n-x)/5); theA[lena=1]=F[x]; the Multoc (); - for(printf ("%lld", C[lenc]), i=lenc-1;i>0; i--){ in for(j=modd/Ten; j;j/=Ten)if(C[I]<J) Putchar ('0'); theprintf"%lld", C[i]); the}puts ("");//printf ("%d\n", Lenc); About } the return 0; the}
View Code
[bzoj3287] Mato's Brush screen plan