Fast Bit Calculations LightOJ - 1032
Fast Bit Calculations LightOJ - 1032
题意:求0到n的所有数的二进制表示中,"11"的总数量。(如果有连续的n(n>2)个1,记(n-1)个"11")
方法:常规数位dp。ans[pos][ans][f][pre0],pos当前位置,ans当前答案,f前一位,pre0是否在前导0
记一下看到的奇怪的做法:http://www.cnblogs.com/WABoss/p/5127652.html
错误(本地):
注意:按这种模板来写数位dp,要求将答案也记录进状态,其含义是当前面产生的答案相同,其他条件相同时,后面产生的答案也相同。
#include<cstdio>
#include<cstring>
typedef long long LL;
LL w[],T,TT,n;
LL ans[][][][];
LL dp(LL pos,LL f,bool pre0,bool limit,LL xx)
{
if(pos<) return pre0?:xx;
if(!limit&&ans[pos][xx][f][pre0]!=-)
return ans[pos][xx][f][pre0];
LL i,res=,end=limit?w[pos]:;
for(i=;i<=end;i++)
res+=dp(pos-,i,pre0&&i==,limit&&i==w[pos],xx+(i==&&f==));
return limit?res:ans[pos][xx][f][pre0]=res;
}
LL get(LL x)
{
LL i;
for(i=;x>;x/=) w[++i]=x%;
return dp(i,,,,);
}
int main()
{
memset(ans,-,sizeof(ans));
scanf("%lld",&T);
for(TT=;TT<=T;TT++)
{
scanf("%lld",&n);
printf("Case %lld: %lld\n",TT,get(n));
}
return ;
}
Fast Bit Calculations LightOJ - 1032的更多相关文章
- [暑假集训--数位dp]LightOj1032 Fast Bit Calculations
A bit is a binary digit, taking a logical value of either 1 or 0 (also referred to as "true&quo ...
- LightOJ 1032 - Fast Bit Calculations 数位DP
http://www.lightoj.com/volume_showproblem.php?problem=1032 题意:问1~N二进制下连续两个1的个数 思路:数位DP,dp[i][j][k]代表 ...
- lightoj 1032 - Fast Bit Calculations(数位dp)
A bit is a binary digit, taking a logical value of either 1 or 0 (also referred to as "true&quo ...
- Light OJ 1032 - Fast Bit Calculations(数学)
题目链接:http://www.lightoj.com/volume_showproblem.php?problem=1032 题目大意:一个十进制数变化为二进制,那么对于这个数,如果连着两个二进制位 ...
- Light OJ 1032 - Fast Bit Calculations(数位DP)
题目大意: 一个数字把他看成二进制数字,数字里又会一些相邻的1,问从0到n至间所有相邻1的总和是多少? 分解成2进制数字,然后数位DP就行了. ======================== ...
- lightoj 1032 二进制的dp
题目链接:http://lightoj.com/volume_showproblem.php?problem=1032 #include <cstdio> #include <cst ...
- LightOJ1032 Fast Bit Calculations(数位DP)
显然数位DP. dp[i][j]表示所有末尾为j的i位二进制数相邻位的数量和 初始状态dp[2][1]=1 从长度i-1转移到长度i就是在i-1位的末尾添上0或1,转移方程就是: dp[i][0]=d ...
- LightOJ - 1032 数位DP
#include<iostream> #include<algorithm> #include<cstdio> #include<cstring> #i ...
- light oj 1032(数位DP)
求一段区间中,每个十进制数所对应的二进制数中连续的1的个数之和. 设dp[i][0]代表长度为i的二进制数,首位为0,所含有的连续的1的个数之和. dp[i][1]代表长度为i的二进制数,首位为1,所 ...
随机推荐
- mysqld与mysqld_safe的区别
文章1: 直接运行mysqld程序来启动MySQL服务的方法很少见,mysqld_safe脚本会在启动MySQL服务器后继续监控其运行情况,并在其死机时重新启动它.用mysqld_safe脚本来启动M ...
- CentOS7虚拟机桥接设置及问题
转载请注明出处:jiq•钦's technical Blog 今天在VMWare WorkStation9中安装了CentOS7虚拟机. 虚拟机与宿主机网络连接有三种方式:桥接模式.NAT模式和Ho ...
- cocos2dx学习进度
将cocos2dx实战上面的例子都自己过一遍,手动敲一边里面的代码,瓦片地图,地图滚动,碰撞,容器类,现在搞到了fileUtils相关的了,哦,官方叫做数据持久化,一不小心就6点了,时间过得太快了,看 ...
- gRPC错误码 http状态码 provide your APIs in both gRPC and RESTful style at the same time
How gRPC error codes map to HTTP status codes in the response https://github.com/grpc-ecosystem/grpc ...
- 20170225-ALV tree 显示
1.写程序, 2.话屏幕9000,CALL SCREEN 9000.(双击屏幕进去画个容器就ok,+OK_CODE,+去掉注释) 3.处理好ALV 的PBO 初始化,处理用户事件PAO,user co ...
- p1199八数码问题
oj上简化的八数码问题,最强的数据仅仅是20步: 根据曼哈顿距离构造启发函数: 主算法:IDA*:(使用方法好像不太对......) 未用位运算优化: #include<iostream> ...
- Centos6.8防火墙设置
# 查看防火墙状态 service iptables status # 停止防火墙 service iptables stop # 启动防火墙 service iptables start ...
- physical processor, core, logical processor
Processor Groups https://docs.microsoft.com/en-us/windows/desktop/ProcThread/processor-groups The 64 ...
- HTML&CSS——background: url() no-repeat 0 -64px;CSS中背景图片定位方法
CSS中背景图片的定位,困扰我很久了.今天总算搞懂了,一定要记下来. 在CSS中,背景图片的定位方法有3种: 1)关键字:background-position: top left; 2)像素:bac ...
- Caused by: java.lang.IllegalArgumentException: Result Maps collection already contains value for com.st.mapper.UserMapper.userBaseMap
mybatis出现此异常,可能是因为 ***Mapper.xml 文件中存在重名对象,一不小心重复启动了mybatis的逆向工程. 以为会覆盖掉以前生成的,没想到是新生成的和之前生成的重复了 解决:把 ...