Digital DP
Windy number on the previous question
Preprocessing to find a combination number
And then the same method, this time, is to record the number of 0 and 1 and then engage
Orz Cxlove
1 /**************************************************************2 problem:16623 User:tunix4 language:c++5 result:accepted6 time:0 Ms7 memory:1280 KB8 ****************************************************************/9 Ten //POJ 3252 && bzoj 1662 One#include <cmath> A#include <vector> -#include <cstdio> -#include <cstring> the#include <cstdlib> -#include <iostream> -#include <algorithm> - #defineRep (i,n) for (int i=0;i<n;++i) + #defineF (i,j,n) for (int i=j;i<=n;++i) - #defineD (i,j,n) for (int i=j;i>=n;--i) + #definePB Push_back A using namespacestd; at intGetint () { - intv=0, sign=1;CharCh=GetChar (); - while(!isdigit (CH)) {if(ch=='-') sign=-1; Ch=GetChar ();} - while(IsDigit (CH)) {v=v*Ten+ch-'0'; Ch=GetChar ();} - returnv*Sign ; - } in Const intn=1e7+Ten, inf=~0u>>2; - Const Doubleeps=1e-8; to /*******************template********************/ + intc[ +][ +]; - voidinit () { thec[0][0]=1; *F (I,1, +){ $c[i][0]=c[i-1][0];Panax NotoginsengF (J,1, i) c[i][j]=c[i-1][j]+c[i-1][j-1]; - } the } + intSolveintN) { A intlen=0, bit[ +],cnt=0; the for(; n;n>>=1) bit[++len]=n&1; + intans=0; -F (I,1, len-1) $D (j,i-1, (i+1) >>1) $ans+=c[i-1][j]; - intOne=1, zero=0; -D (i,len-1,1) the if(Bit[i]) { -zero++;WuyiF (J,max (0, (len+1)/2-zero), I-1) theans+=c[i-1][j]; -zero--; Wuone++; - } About Elsezero++; $ //ans+=c[cnt-1][(len+1) >>1]; - returnans; - } - intMain () { A init (); + intL=getint (), r=getint (); theprintf"%d\n", Solve (r+1)-solve (L)); - return 0; $}
View Code
"Bzoj" "1662"/"POJ" "3252" "Usaco 2006 Nov" Round number