POI2007 the end of the flower ~
First convert N to quad, from low to high DP
F[i] Indicates that this bit is not down a borrow
G[i] means that this bit down a borrow, but the borrowed one is not counted in I
F[0]=0,g[0]=inf
F[i]=merge (f[i-1]+b[i],g[i-1]+b[i]+1)
G[i]=merge (F[i-1]+4-b[i],g[i-1]+3-b[i])
#include <cstdio> #include <cstring> #define N 1670struct e{ int x, y; E () {} e (int _x,int _y) {x=_x,y=_y;} inline e operator+ (int _x) {return E (x+_x,y);} Inline e operator+ (e b) {return x==b.x? E (x, (Y+B.Y)%1000000000):(x<b.x? E (x, y): b);}} F[n],g[n];int L,n,i,a[n],b[n];char S[n];int Main () {for (scanf ("%s", s), L=std::strlen (s), i=1;i<=l;i++) a[i]=s [l-i]-' 0 '; while (l) {for (i=l,a[0]=0;i;i--) a[i-1]+= (a[i]&3) *10,a[i]>>=2; for (b[++n]=a[0]/10;l&&!a[l];l--); } For (F[0]=e (0,1), g[0]=e (n,0), n++,i=1;i<=n;i++) f[i]= (F[i-1]+b[i]) + (g[i-1]+ (b[i]+1)), g[i]= (f[i-1]+ (4-b[i))) + (g [I-1]+ (3-b[i])); Return printf ("%d", f[n].y), 0;}
BZOJ1111: [POI2007] Four-step balance WAG