poj3252 Round Numbers[数位DP]
拆成2进制位做dp记搜就行了,带一下前导0,将0和1的个数带到状态里面,每种0和1的个数讨论一下,累加即可。
WA记录:line29。
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#define dbg(x) cerr<<#x<<" = "<<x<<endl using namespace std;
typedef long long ll;
template<typename T>inline char MIN(T&A,T B){return A>B?A=B,:;}
template<typename T>inline char MAX(T&A,T B){return A<B?A=B,:;}
template<typename T>inline T _min(T A,T B){return A<B?A:B;}
template<typename T>inline T _max(T A,T B){return A>B?A:B;}
template<typename T>inline T read(T&x){
x=;int f=;char c;while(!isdigit(c=getchar()))if(c=='-')f=;
while(isdigit(c))x=x*+(c&),c=getchar();return f?x=-x:x;
}
int f[][][][],b[];
int l,r;
int dp(int len,int s0,int s1,bool lead,bool limit){//ddddbg(len,s0,s1,lead);dbg(limit);
if(s0<||s1<||s0+s1>len||(!lead&&(s0+s1)^len))return ;
if(!len&&!s0&&!s1)return ;
if(!limit&&~f[len][s0][s1][lead])return f[len][s0][s1][lead];
int cnt=,num=limit?b[len]:;
if(lead)cnt+=dp(len-,s0,s1,,limit&&!num);//填0
else cnt+=dp(len-,s0-,s1,,limit&&!num);
if(num)cnt+=dp(len-,s0,s1-,,limit);//填1
return limit?cnt:f[len][s0][s1][lead]=cnt;
}//没有乖乖套模板卡上界判断写错了
inline int solve(int x){
int k=,cnt=;while(x)b[++k]=x&,x>>=;
for(register int i=;i<k;++i)for(register int j=;j<=_min(i,k-i);++j)cnt+=dp(k,i,j,,);
return cnt;
} int main(){//freopen("tmp.txt","r",stdin);//freopen("test.out","w",stdout);
memset(f,-1,sizeof f);read(l),read(r);
return printf("%d\n",solve(r)-solve(l-)),;
}
poj3252 Round Numbers[数位DP]的更多相关文章
- POJ3252 Round Numbers —— 数位DP
题目链接:http://poj.org/problem?id=3252 Round Numbers Time Limit: 2000MS Memory Limit: 65536K Total Su ...
- poj3252 Round Numbers (数位dp)
Description The cows, as you know, have no fingers or thumbs and thus are unable to play Scissors, P ...
- 【poj3252】 Round Numbers (数位DP+记忆化DFS)
题目大意:给你一个区间$[l,r]$,求在该区间内有多少整数在二进制下$0$的数量$≥1$的数量.数据范围$1≤l,r≤2*10^{9}$. 第一次用记忆化dfs写数位dp,感觉神清气爽~(原谅我这个 ...
- [poj3252]Round Numbers_数位dp
Round Numbers poj3252 题目大意:求一段区间内Round Numbers的个数. 注释:如果一个数的二进制表示中0的个数不少于1的个数,我们就说这个数是Round Number.给 ...
- poj 3252 Round Numbers(数位dp 处理前导零)
Description The cows, as you know, have no fingers or thumbs and thus are unable to play Scissors, P ...
- 4-圆数Round Numbers(数位dp)
Round Numbers Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 14947 Accepted: 6023 De ...
- POJ 3252 Round Numbers(数位dp&记忆化搜索)
题目链接:[kuangbin带你飞]专题十五 数位DP E - Round Numbers 题意 给定区间.求转化为二进制后当中0比1多或相等的数字的个数. 思路 将数字转化为二进制进行数位dp,由于 ...
- POJ - 3252 - Round Numbers(数位DP)
链接: https://vjudge.net/problem/POJ-3252 题意: The cows, as you know, have no fingers or thumbs and thu ...
- Round Numbers(数位DP)
Round Numbers http://poj.org/problem?id=3252 Time Limit: 2000MS Memory Limit: 65536K Total Submiss ...
随机推荐
- Latex中參考文献排序
\bibliographystyle{unsrt}:依照引用的先后排序 \bibliographystyle{plain}:按字母的顺序排列,比較次序为作者.年度和标题.当中作者中姓氏字母优先. 关于 ...
- 计算点与x轴正半轴夹角atan2(double y,double x),返回弧度制(-PI,PI]
精度比acos , asin 什么的高些. Parameters y Value representing the proportion of the y-coordinate. x Value re ...
- 【BZOJ3769】spoj 8549 BST again DP(记忆化搜索?)
[BZOJ3769]spoj 8549 BST again Description 求有多少棵大小为n的深度为h的二叉树.(树根深度为0:左右子树有别:答案对1000000007取模) Input 第 ...
- 【BZOJ4069】[Apio2015]巴厘岛的雕塑 按位贪心+DP
[BZOJ4069][Apio2015]巴厘岛的雕塑 Description 印尼巴厘岛的公路上有许多的雕塑,我们来关注它的一条主干道. 在这条主干道上一共有 N 座雕塑,为方便起见,我们把这些雕塑从 ...
- Webpack探索【3】--- loader详解
本文主要说明Webpack的loader相关内容.
- C调用Lua中的函数解析table
Passing Tables to Lua Functions A use case that happens often is the passing of tables to and from L ...
- Windows磁盘MBR结构详解
在之前的文章 Windows存储管理之磁盘结构详解 中介绍了Windows的磁盘结构和MBR.本文将对Windows Basic Disk中的MBR的结构进行介绍,帮助读者更好的了解Windows系统 ...
- secureCRT linux shell显示中文乱码 解决方法
引:有没有这样的经历: 1.在shell中直接查看包含中文的文件时,出现一堆火星文,不得不下载下来window看. 2.无法正常的在shell中输入中文. 3.make的时候输出一堆乱码. 以下是查阅 ...
- ubuntu service XXX start启动报start: Rejected send message, 1 matche
service cron restart命令报错如下: stop: Rejected send message, 1 matched rules; type="method_call&quo ...
- dev系列之gridview
gridview新增一行就激活编辑,及显示闪动的光标 gridView1.ShowEditor(); 隐藏Gridview表头上面的panel this.gridView1.OptionsView.S ...