POJ 3252 Round Numbers

Source: Internet
Author: User

Title Link: http://poj.org/problem?id=3252

Test instructions: If a binary representation of a number is greater than or equal to 1 of the number of its 0, then this is a round Numbers.

Give an interval and ask how many round Numbers there are in this interval.

Ideas:

Memory search, judge the last number of 0 and 1 of the number, but pay attention to the leading 0 case, the number of leading 0 is removed.

1#include <iostream>2#include <cstring>3#include <cstdio>4 using namespacestd;5 intnum[ +];6 intdp[ +][2][ +][ +];7 intDfsintCurintAllzero,intOneintZerointlimit)8 {9     if(Cur <0)Ten     { One         if(!allzero && (zero >= One))return 1; A         Else return 0; -     } -     if(!limit && Dp[cur][allzero][one][zero]! =-1)returnDp[cur][allzero][one][zero]; the      -     intRET =0; -     intup = Limit?num[cur]:1; -      for(inti =0; I <= up; i++) +     { -         if(i = =0&& Allzero = =0) ret + = DFS (cur-1, Allzero, one, zero+1, limit && i = =Up );  +         Else if(i = =0&& Allzero = =1) ret + = DFS (cur-1, Allzero,0,0, limit && i = =Up ); A         Else if(i = =1&& Allzero = =0) ret + = DFS (cur-1, Allzero, one+1, zero, limit && i = =Up ); at         Else if(i = =1&& Allzero = =1) ret + = DFS (cur-1,0, one+1, zero, limit && i = =Up );  -     } -     if(!limit) Dp[cur][allzero][one][zero] =ret; -     returnret; - } - intSlove (intx) in { -Memset (DP,-1,sizeof(DP)); to     intCNT =0; +      while(x) -     { thenum[cnt++] = x percent2; *X/=2; $     }Panax Notoginseng     returnDFS (cnt-1,1,0,0,1); -      the } + intMain () A { the    //freopen ("In.txt", "R", stdin); +    //freopen ("OUT.txt", "w", stdout); -     intN, M; $      while(~SCANF ("%d%d", &n, &m)) $     { -printf"%d\n", Slove (m)-Slove (n1)); -     } the     return 0; -}

POJ 3252 Round Numbers

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.