"Bzoj" "1662"/"POJ" "3252" "Usaco 2006 Nov" Round number

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.