poj 3252 Round Numbers 数位dp
找一个范围内二进制中0的个数大于等于1的个数的数的数量。基础的数位dp
#include<bits/stdc++.h>
using namespace std;
#define mem1(a) memset(a, -1, sizeof(a))
int digit[], dp[][][], len;
int dfs(int len, int num0, int num1, int f, int first) { //first记录前面是否全部为0
if(!len) {
return num0>=num1;
}
if(!f&&!first&&dp[len][num0][num1]!=-)
return dp[len][num0][num1];
int ret = , maxx = f?digit[len]:;
for(int i = ; i<=maxx; i++) {
if(i == ) {
ret += dfs(len-, first?:num0+, num1, f&&i==maxx, first);
} else {
ret += dfs(len-, num0, num1+, f&&i==maxx, );
}
}
if(!f&&!first)
return dp[len][num0][num1] = ret;
return ret;
}
int cal(int n) {
len = ;
while(n) {
digit[++len] = n&;
n>>=;
}
return dfs(len, , , , );
}
int main()
{
int a, b;
mem1(dp);
while(~scanf("%d%d", &a, &b)) {
printf("%d\n", cal(b)-cal(a-));
}
}
poj 3252 Round Numbers 数位dp的更多相关文章
- poj 3252 Round Numbers(数位dp 处理前导零)
Description The cows, as you know, have no fingers or thumbs and thus are unable to play Scissors, P ...
- 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 ...
- $POJ$3252 $Round\ Numbers$ 数位$dp$
正解:数位$dp$ 解题报告: 传送门$w$ 沉迷写博客,,,不想做题,,,$QAQ$口胡一时爽一直口胡一直爽$QAQ$ 先港下题目大意嗷$QwQ$大概就说,给定区间$[l,r]$,求区间内满足二进制 ...
- POJ3252 Round Numbers —— 数位DP
题目链接:http://poj.org/problem?id=3252 Round Numbers Time Limit: 2000MS Memory Limit: 65536K Total Su ...
- Round Numbers(数位DP)
Round Numbers http://poj.org/problem?id=3252 Time Limit: 2000MS Memory Limit: 65536K Total Submiss ...
- POJ 3252 Round Numbers(组合)
题目链接:http://poj.org/problem?id=3252 题意: 一个数的二进制表示中0的个数大于等于1的个数则称作Round Numbers.求区间[L,R]内的 Round Numb ...
- 4-圆数Round Numbers(数位dp)
Round Numbers Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 14947 Accepted: 6023 De ...
- poj3252 Round Numbers (数位dp)
Description The cows, as you know, have no fingers or thumbs and thus are unable to play Scissors, P ...
随机推荐
- 分享:一个基于NPOI的excel导入导出组件(强类型)
一.引子 新进公司被安排处理系统的数据报表任务——对学生的考试成绩进行统计并能导出到excel.虽然以前也有弄过,但感觉不是很好,所以这次狠下心,多花点时间作个让自己满意的插件. 二.适用领域 因为需 ...
- C# GridView弹出窗口新增行 删除行
<%@ Page Language="C#" AutoEventWireup="true" EnableViewState="true" ...
- 学习dijk最短路径中
#include<iostream> #include<math.h> #include<stdio.h> #include<algorithm> #i ...
- Labview常用快捷键
对象调整和移动快捷键 Shift-click 选择多个对象,在现有选择的基础上添加对象 方向键 ...
- Javascript中的attribute和property分析
attribute和property这两个单词,都有属性的意思,attribute有属性.特质的意思,property则有性质,性能的意思. 首先需要明确的是,在规范中,读取和设置attribute的 ...
- You have not agreed to the Xcode license.
You have not agreed to the Xcode license. Before running the installer again please agree to the lic ...
- PHP fopen和fwrite函数实现创建html页面
思路 用fopen函数和fread函数得到模板,然后用str_replace函数替换模板标签为变量,最后用fwrite函数输出新的HTML页面 index.html模板页面 <!DOCTYPE ...
- Android IT资讯网络阅读器应用源码
这个是Android IT资讯网络阅读器应用,也是一款通过jsoup解析Html获取内容的网络阅读器,和前面的其实是类似的,也是大学时期闲暇完成,对照CSDN的Web页面元素设计进行解析提取内容,核心 ...
- 50行实现简易HTTP服务器
话说由于一直很懒,所以博客好像也没怎么更新...今天有空就写一下吧. 最近在看node.js的时候开始对http协议感兴趣了,毕竟node一开始就是为了做web服务器而产生的.于是试着想了一下大概的思 ...
- Prepare Python environment and install selenium.
1, Install python and selenium. I use python 3.5, the following is the example 1.) Python downloa ...