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,所 ...
随机推荐
- Shell hook
[目的]实现 ll -as +hook+ clear Shell脚本及钩子 - CSDN博客 https://blog.csdn.net/shengzhu1/article/details ...
- Golang 现有的哲学中,要求你尽量手工处理所有的错误返回
更优雅的 Golang 错误处理 - Go语言中文网 - Golang中文社区 https://studygolang.com/articles/9407
- SpringMVC 之 Controller、Service层职责
Controller层 1.接收httpRequest/requestDTO数据 ,检查接收数据参数与格式. 2.传递参数至Service层并接收返回responseDTO数据. 3.包装respon ...
- [翻译]Unity中的AssetBundle详解(三)
构建AssetBundles 在AssetBundle工作流程的文档中,我们有一个示例代码,它将三个参数传递给BuildPipeline.BuildAssetBundles函数.让我们更深入地了解我们 ...
- android 提示
1.Toast: Toast toast=new Toast(context); Toast.makeText(context, text, duration);//返回值为Toast toast.s ...
- Spring boot 使用Junt
//@RunWith:启动器,SpringJUnit4ClassRunner:Spring整合JUnit4 //@SpringBootTest获取启动类,相当于@Contextconfiguartio ...
- 解决ubuntu没有/var/log/messages的问题
1:root身份打开 /etc/rsyslog.d/50-default.conf 2:把注释#去掉 #*.=info;*.=notice;*.=warn;\ # auth,authpriv.none ...
- axios基于常见业务场景的二次封装
axios axios 是一个基于 promise 的 HTTP 库,可以用在浏览器和 node.js 中.在前端框架中的应用也是特别广泛,不管是vue还是react,都有很多项目用axios作为网络 ...
- POJ1077 Eight —— 经典的搜索问题
题目链接:http://poj.org/problem?id=1077 Eight Time Limit: 1000MS Memory Limit: 65536K Total Submission ...
- 【SOUTH CENTRAL USA 1998】 eight
[题目链接] 点击打开链接 [算法] 这是经典的八数码问题,据说此题不做人生不完整 这里笔者用的是双向广搜,由于细节较多,笔者花了3h才通过此题 [代码] #include <algorithm ...