POJ 3252 Round Numbers (区间DP,基础)
题意:
统计区间[L,R]有多少个数,其二进制表示法中的0的个数不少于1的个数?(不允许前缀0)
思路:
状态表示为 [当前第几位][总位数][1的个数],最后判断一下1的个数是否满足条件,要注意前导0的问题,可以通过枚举二进制的位数来解决。
//#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <map>
#include <algorithm>
#include <vector>
#include <iostream>
#define pii pair<int,int>
#define INF 0x7f3f3f3f
#define LL long long
#define ULL unsigned long long
using namespace std;
const double PI = acos(-1.0);
const int N=; int f[N][N][N], bit[N];
//[当前第几位][总位数][1的个数]
int dfs(int i,int up,int cnt,bool e)
{
if(i==) return cnt*<=up;
if(!e && ~f[i][up][cnt]) return f[i][up][cnt];
if(cnt*>up) return ; int ans=;
int d= i==up?:;
int u= e? bit[i]: ;
for( ; d<=u; d++)
{
ans+=dfs(i-,up,cnt+d,e&&d==u);
}
return e? ans: f[i][up][cnt]=ans;
} int cal(int n)
{
if(n<=) return ;
int len=;
while(n) //拆数
{
bit[++len]=(n&);
n>>=;
}
int ans=;
for(int i=; i<len; i++) ans+=dfs(i,i,,false);
ans+=dfs(len,len,,true);
return ans;
} int main()
{
//freopen("input.txt","r",stdin);
memset(f, -, sizeof(f));
int a, b;
scanf("%d%d",&a,&b);
printf("%d\n",cal(b)-cal(a-) ); return ;
}
AC代码
POJ 3252 Round Numbers (区间DP,基础)的更多相关文章
- POJ 3252 Round Numbers(数位dp&记忆化搜索)
题目链接:[kuangbin带你飞]专题十五 数位DP E - Round Numbers 题意 给定区间.求转化为二进制后当中0比1多或相等的数字的个数. 思路 将数字转化为二进制进行数位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)
链接: https://vjudge.net/problem/POJ-3252 题意: The cows, as you know, have no fingers or thumbs and thu ...
- poj 3252 Round Numbers 数位dp
题目链接 找一个范围内二进制中0的个数大于等于1的个数的数的数量.基础的数位dp #include<bits/stdc++.h> using namespace std; #define ...
- $POJ$3252 $Round\ Numbers$ 数位$dp$
正解:数位$dp$ 解题报告: 传送门$w$ 沉迷写博客,,,不想做题,,,$QAQ$口胡一时爽一直口胡一直爽$QAQ$ 先港下题目大意嗷$QwQ$大概就说,给定区间$[l,r]$,求区间内满足二进制 ...
- POJ 3252 Round Numbers(组合)
题目链接:http://poj.org/problem?id=3252 题意: 一个数的二进制表示中0的个数大于等于1的个数则称作Round Numbers.求区间[L,R]内的 Round Numb ...
- [ACM] POJ 3252 Round Numbers (的范围内的二元0数大于或等于1数的数目,组合)
Round Numbers Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 8590 Accepted: 3003 Des ...
- POJ 3252 Round Numbers
组合数学...(每做一题都是这么艰难) Round Numbers Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 7607 A ...
- POJ 3252 Round Numbers 数学题解
Description The cows, as you know, have no fingers or thumbs and thus are unable to play Scissors, P ...
- POJ 3252 Round Numbers 组合数学
Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 13381 Accepted: 5208 Description The ...
随机推荐
- UVa 11100 The Trip, 2007 (题意+贪心)
题意:有n个包,其中小包可以装到大的包里,包的大小用数字进行表示,求最小的装包数量. 析:这个题的题意不太好理解,主要是有一句话难懂,意思是让每个最大包里的小包数量的最大值尽量小,所以我们就不能随便输 ...
- string实现
#include<iostream> using namespace std; class String{ friend ostream& operator<&l ...
- FZU - 2218 Simple String Problem(状压dp)
Simple String Problem Recently, you have found your interest in string theory. Here is an interestin ...
- SVN版本控制图标未显示或显示异常解决方法
SVN版本控制图标未显示问题解决方法,刚开始遇到这个问题的时候,好苦恼.经过“千辛万苦”的努力,终于得以解决,分享给大家,希望能帮到各位哦! 工具/原料 SVN安装包 方法/步骤 首先安装 ...
- ue4 官网IK流程记录
基本流程 角色蓝图构造 角色蓝图 角色蓝图中新建的函数IK Foot Trace AnimGraph事件 这里注意下Make Vector时把z方向的偏移量设置到了X上 猜测原因是效应器的x方向跟世界 ...
- ShellExecute
有三个API函数可以运行可执行文件WinExec.ShellExecute和CreateProcess. 1.CreateProcess因为使用复杂,比较少用. 2.WinExec主要运行EXE文件. ...
- codevs1105 过河
1105 过河 2005年NOIP全国联赛提高组 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 钻石 Diamond 题解 题目描述 Description 在河上有一座独木桥,一 ...
- 洛谷P3959 宝藏(状压dp)
传送门 为什么感觉状压dp都好玄学……FlashHu大佬太强啦…… 设$f_{i,j}$表示当前选的点集为$i$,下一次要加入的点集为$j$时,新加入的点和原有的点之间的最小边权.具体的转移可以枚举$ ...
- MySQL下载与安装配置
一.Windows 上安装 MySQL Windows 上安装 MySQL 相对简单,最新版本下载地址: 官网:https://dev.mysql.com/downloads/mysql/ 下载步骤: ...
- MySQL (case when then else end)和常用函数用法
case when then else end 相当于Java的if-else if-else,可以用来在select语句中将要显示的内容替换成另一个内容 更多用法:https://www.cnblo ...