Light OJ 1032 - Fast Bit Calculations(数位DP)
题目大意:
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<queue>
#include<vector>
#include<map>
using namespace std;
typedef long long LL;
const int INF = 1e9+;
const int MAXN = ;
int bit[];///dp[位数][首位是否是1]
LL dp[][][];
LL DFS(int pos,int num,bool Is1,int Lim)///num代表这个数字里面成对的
{
if(pos == -)
return num;
if(dp[pos][num][Is1] != - && !Lim)
return dp[pos][num][Is1];
int end = Lim?bit[pos]:; LL ans = , k = ;
for(int i=; i<=end; i++)
{
if(i == && Is1) k = ;
ans += DFS(pos-, num+k, i==, Lim && i==end);
}
if(!Lim)
dp[pos][num][Is1] = ans;
return ans;
} LL solve(int n)
{
int len = ;
while(n)
{
bit[len++] = n%;
n /= ;
}
return DFS(len-, , false, true);
}
int main()
{
int T, cas = , n;
memset(dp, -, sizeof(dp));
scanf("%d", &T);
while(T --)
{
scanf("%d", &n);
printf("Case %d: %lld\n",cas++, solve(n));
} return ;
}
Light OJ 1032 - Fast Bit Calculations(数位DP)的更多相关文章
- LightOJ 1032 - Fast Bit Calculations 数位DP
http://www.lightoj.com/volume_showproblem.php?problem=1032 题意:问1~N二进制下连续两个1的个数 思路:数位DP,dp[i][j][k]代表 ...
- Light OJ 1032 - Fast Bit Calculations(数学)
题目链接:http://www.lightoj.com/volume_showproblem.php?problem=1032 题目大意:一个十进制数变化为二进制,那么对于这个数,如果连着两个二进制位 ...
- light oj 1140 - How Many Zeroes? 数位DP
思路:dp[i][j]:表示第i位数,j表示是否有0. 代码如下: #include<iostream> #include<stdio.h> #include<algor ...
- light oj 1032(数位DP)
求一段区间中,每个十进制数所对应的二进制数中连续的1的个数之和. 设dp[i][0]代表长度为i的二进制数,首位为0,所含有的连续的1的个数之和. dp[i][1]代表长度为i的二进制数,首位为1,所 ...
- 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
数位dp,许多数位dp需要统计某种模式(子串)出现的数量,这种题通常需要在递归参数中加入高位已经出现过的模式的数量. #include <cstdio> #include <cstr ...
- Light OJ 1031 - Easy Game(区间DP)
题目大意: 给你一个n,代表n个数字,现在有两个选手,选手A,B轮流有有一次机会,每个选手一次可以得到一个或者多个数字,从左侧或者右侧,但是不能同时从两边取数字,当所有的数字被取完,那么游戏结束.然后 ...
- Light OJ 1021 - Painful Bases(状态压缩DP)
题目大意: 给你一个base 进制的数字,把这个数字的每一位进行全排列,问有多少个数字是可以整除k的. 题目解析: #include<cstdio> #include<cstring ...
- Light OJ 1004 - Monkey Banana Problem(DP)
题目大意: 给你一菱形的数字阵,问从最上面走到最下面所能获得的最大值是多少? #include<cstdio> #include<cstring> #include<io ...
随机推荐
- 隐藏元素的宽高无法通过原生js获取的问题
1.起源:移动app项目中,页面加载时需要加载国家下拉列表,将隐藏的透明浮层和一个显示加载过程中的框 显示出来,隐藏的透明浮层设置宽高都是100%即可,而这个加载提示框需要先得出它的宽高,然后再根据页 ...
- css:nth-of-type()选择器用法
今天做一个页面,无意中看到这个nth-of-type感觉挺方便的,之前单双行有的有横线,有的无横线一般在html中单独再写border-right:none等之类的.现在发现这个好东西赶紧记录下来. ...
- 【原创教程】鲸吞HTML
首先,我们的angularJS课程分为三大模块: HTML/CSS/JS基础. angularJS详解. angualrJS的一些实用框架讲解. 其中,第一大模块的对象是对前端开发技术有点了解但不熟悉 ...
- github上建站和使用markdown写文章
积累了那么久,终于成功搭建了github上的个人网站.虽然方法有点巧妙.不是还是建成了 同时学会用markdown写基本的文章.感觉还可以.附带我的github上的静态页面网站的网址:http://z ...
- 求职,找工作,平台大PK
国内 猎聘网:www.lietou.com 拉钩网:Lagou.com 智联招聘:www.zhaopin.com 前程无忧:http://www.51job.com/ 中华英才网:chinahr.co ...
- js关闭窗口
window.close() window.open("about:blank","_self").close() window.open("&quo ...
- [转]setTimeout() 函数未定义错误
用 setTimeout("showMe()",1000) 时出现 showMe is not defined 错误.这是由于showMe() 函数不在 setTimeout 调用 ...
- 使用Eclipse把java文件打包成jar 含有第三方jar库的jar包
使用Eclipse把java文件打包成jar 含有第三方jar库的jar包 网上打包说用eclipse安装fat jar插件,但是貌似现在都不能用了,所以我只能按照eclipse自带的方法打包了. ...
- Fatal error: Uncaught SoapFault exception
Warning: SoapClient::SoapClient() expects parameter 2 to be array, boolean given in login\login.php ...
- /etc/fstab一些信息
[root@shine shine]# vim /etc/fstab ## /etc/fstab# Created by anaconda on Thu May 9 13:29:35 2013## A ...