POJ-3252 Avenger
题意:在区间中,他们化成2进制的数的0的个数大于等于1的数有多少个。
思路:我们需要记录上一次0和1的个数,此外我们还要特别注意一下前导0。
如果前面全是0的时候我们就要注意下一位是不是还是0,如果一直都是0那么这个数也满足条件。
/* gyt
Live up to every day */
#include<cstdio>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<cstring>
#include<queue>
#include<set>
#include<string>
#include<map>
#include <time.h>
#define PI acos(-1)
using namespace std;
typedef long long ll;
typedef double db;
const int maxn = +;
const ll maxm = 1e7;
const int mod = ;
const int INF = <<;
const db eps = 1e-;
const ll Max=1e19;
int a[maxn];
ll dp[maxn][maxn][maxn]; ll dfs(int pos, int num0, int num1, int limit, int ncan) {
if (pos==-) {
if (ncan) return ;
if (num0>=num1) return ;
return ;
}
if (!limit && !ncan && dp[pos][num0][num1]!=-) return dp[pos][num0][num1];
int up=limit?a[pos]:;
ll tmp=;
for (int i=; i<=up; i++) {
if (ncan) {
if (i==)
tmp+=dfs(pos-, , , limit&&i==a[pos], );
else
tmp+=dfs(pos-, , , limit&&i==a[pos], );
}
else {
if (i==)
tmp+=dfs(pos-, num0+, num1, limit&&i==a[pos], );
else
tmp+=dfs(pos-, num0, num1+, limit&&i==a[pos], );
}
}
if (!limit) dp[pos][num0][num1]=tmp;
return tmp;
}
ll deal(ll x) {
int pos=;
while(x) {
a[pos++]=x%;
x/=;
}
dfs(pos-, , , , );
}
void solve() {
ll n, m; scanf("%lld%lld", &n, &m);
memset(dp, -, sizeof(dp));
ll a=deal(m), b=deal(n-);
//cout<<a<<" "<<b<<endl;
printf("%lld\n", a-b);
}
int main() {
int t=;
//freopen("in.txt", "r", stdin);
//scanf("%d", &t);
for (int T=; T<=t; T++) {
solve();
}
}
POJ-3252 Avenger的更多相关文章
- POJ 3252 (数位DP)
###POJ 3252 题目链接 ### 题目大意:给你一段区间 [Start,Finish] ,在这段区间中有多少个数的二进制表示下,0 的个数 大于等于 1 的个数. 分析: 1.很显然是数位DP ...
- POJ 3252:Round Numbers
POJ 3252:Round Numbers Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 10099 Accepted: 36 ...
- POJ 3252 Round Numbers(组合)
题目链接:http://poj.org/problem?id=3252 题意: 一个数的二进制表示中0的个数大于等于1的个数则称作Round Numbers.求区间[L,R]内的 Round Numb ...
- poj 3252
http://poj.org/problem?id=3252//自己搞了很长时间...现在刚刚有点明白.. 1 #include <iostream> using namespace st ...
- [poj 3252]数位dp前导0的处理
通过这个题对于数位dp中前导0的处理有了新的认识. 题目链接:http://poj.org/problem?id=3252 //http://poj.org/problem?id=3252 #incl ...
- poj 3252 Round Numbers 【推导·排列组合】
以sample为例子 [2,12]区间的RoundNumbers(简称RN)个数:Rn[2,12]=Rn[0,12]-Rn[0,1] 即:Rn[start,finish]=Rn[0,finish]-R ...
- POJ 3252 Round Numbers
组合数学...(每做一题都是这么艰难) Round Numbers Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 7607 A ...
- Greedy:Fence Repair(POJ 3252)
Fence Repair 问题大意:农夫约翰为了修理栅栏,要将一块很长的木块切割成N块,准备切成的木板的长度为L1,L2...LN,未切割前的木板的长度恰好为切割后木板的长度的总和,每次切断木板的时候 ...
- poj 3252 组合数
主要考察组合数知识,初始化的时候参考公式 首先先推个公式,就是长度为len的Round Numbers的个数. 长度为len,第一位肯定是1了. 那么后面剩下 len-1位 ...
- POJ 3252 Round Numbers(数位dp)
题意:给定区间[l,r],l < r ,求区间中满足条件的正整数的个数:二进制表示下0的个数不少于1的个数. 分析:f(x)表示<=x时满足条件的数的个数,所求问题即为f(r)-f(l-1 ...
随机推荐
- CUDA error 100 & Decoder not initialized
项目中用cuda解码时候遇到该错误,这是调用cuda相关库中一些so库版本错误造成的.
- Toolbar 工具栏 菜单 标题栏 Menu
要使用Toolbar,要先将标题栏(ActionBar)关掉: style.xml中:<style name="MainActivityTheme" parent=" ...
- 微信小程序开发——setData的使用技巧
前言: 之前使用 setData,一直都是作为给变量赋值,感觉比起vue给data中的变量的赋值还是有点麻烦的. 最近项目不太紧张,为了提高小程序的开发效率及提升小程序开发的能力,又重新的通读了下小程 ...
- 在IDEA中使用MyBatis Generator逆向工程生成代码
本文介绍一下用Maven工具如何生成Mybatis的代码及映射的文件. 一.配置Maven pom.xml 文件 在pom.xml增加以下插件: <build> <finalName ...
- ACM-ICPC 2018 南京赛区网络预赛 G. Lpl and Energy-saving Lamps(二分+线段树区间最小)
During tea-drinking, princess, amongst other things, asked why has such a good-natured and cute Drag ...
- pycharm中conda环境部署
问题 pycharm中部署了conda base环境,项目中 import sklearn 报错,缺少DLL模块 . 但是在Anaconda Prompt中 import sklearn 则成功. 发 ...
- JAVA EXAM2 复习提纲
[真假分数相加] //inheritence, extends, use this & super 子类的方法 //two constructors, non-default use 'thi ...
- Shell脚本break和continue命令
在循环过程中,有时候需要在未达到循环结束条件时强制跳出循环,Shell使用 break 和 continue 来跳出循环. break命令 允许跳出所有循环(终止执行后面的所有循环). continu ...
- input,textarea在ios和Android上阴影和边框的处理方法(在移动端)
1.去掉ios上阴影的方法只需要在css文件上添加input,textarea{-webkit-appearance: none;}就可以了 2.在移动端上input和textarea边框问题,也是在 ...
- localstorage和vue结合使用2
html <template> <div class="hello"> <div class="page-top"> < ...