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,所 ...
随机推荐
- Appium,IOS 模拟器,Java工程搭建
首先进入sample code Test App 有TestApp.xcodeproj文件的工程目录下 下编译出TestApp.app文件 1.新建 java 工程 2.import需要的包 新建cl ...
- VC FTP服务器程序分析(一)
想在QT上移植一个FTP服务器程序,先学习windows下的FTP服务器例子,然后随便动手写点东西. 在pudn上搜索 "FTP服务器端和客户端实现 VC“这几个关键字,就可以搜到下面要分析 ...
- linux杀死进程
http://blog.csdn.net/andy572633/article/details/7211546 ps -ef | grep firefox kill -s 9 1827
- 贞鱼传教&&贞鱼传教(数据加强版)
http://acm.buaa.edu.cn/problem/1381/ 贞鱼传教[问题描述] 新的一年到来了,贞鱼哥决定到世界各地传授“贞教”,他想让“贞教”在2016年成为世界第四大宗教.说干就干 ...
- kbmMW 5.0.1发布了(跨全平台,包括Linux,可使用Win的高性能HTTPSys传输层,等等)
kbmMW5如期发布,作者增加了很多重磅功能,以下翻译作者的发布文件:1.支持Delphi 10.2 Tokyo,包括Linux支持(测试版)2.大量的新功能与改进3.新的智能服务(Smart ser ...
- android提权漏洞CVE-2010-EASY修复【转】
本文转载自: http://blog.csdn.net/lhj0711010212/article/details/9351131 android提权漏洞CVE-2010-EASY修复 linux ...
- POJ2195 Going Home —— 最大权匹配 or 最小费用最大流
题目链接:https://vjudge.net/problem/POJ-2195 Going Home Time Limit: 1000MS Memory Limit: 65536K Total ...
- sql server filter table name
https://stackoverflow.com/questions/26577464/how-to-find-a-table-in-sql-server-if-only-the-partial-t ...
- fuse的编译安装(Centos7-minimal)
打算寒假在家跟着THU的一个分布式系统的课程:http://thu-cmu.cs.tsinghua.edu.cn/curriculum/dscourse/schedule.htm 第0个lab就是要在 ...
- 探索Oracle11gR2 之 DataGuard 三种保护模式
Oracle的DataGuard技术有三种实现模式,分别是max performance.max availability.maxprotection这三种模式. 以下是来自Oracle文档的摘要信息 ...