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 ...
随机推荐
- jdk各版本名称
- WDlinux 修改后台默认8080端口的方法
修改8080端口正确方法 新版本: 方法一: apache sed -i 's/8080/8088/' /www/wdlinux/wdapache/conf/httpd.conf 然后记得修改防火墙i ...
- spring boot 启动错误:Could not resolve placeholder
在启动整个spring boot项目时,出现错误: Could not resolve placeholder 原因:没有指定好配置文件,因为src/main/resources下有多个配置文件,例如 ...
- 第十一章 串 (b2)蛮力匹配
- java里面获取map的key和value的方法
获取map的key和value的方法分为两种形式: map.keySet():先获取map的key,然后根据key获取对应的value: map..entrySet():同时查询map的key和val ...
- POJ-1458.CommonSubsequence.(DP:最长公共子序列裸题)
本题大意:给出两个字符串,让你求出最长公共子序列的长度并输出. 本题思路:本题是经典的DP问题,由于是两个字符串,那么我们就用一个二维数组来进行区分,用dp[ i ][ j ]来表示在s1和s2中分别 ...
- Fraction to Recurring Decimal(STRING-TYPE CONVERTION)
QUESTION Given two integers representing the numerator and denominator of a fraction, return the fra ...
- Android系统显示原理
Android的显示过程可以概括为:Android应用程序把经过测量.布局.绘制后的surface缓存数据,通过SurfaceFlinger把数据渲染到屏幕上,通过Android的刷新机制来刷新数据. ...
- 32-改变eclipse默认的Tomcat部署路径
转载:https://www.cnblogs.com/helf/p/9433588.html eclipse中默认的项目部署路径是在项目的路径,不像myeclipse那样部署后项目在Tomcat的安装 ...
- vue 内引入jquery
1. npm i jquery -- save 2. import $ from 'jquery' window.$ = $ window.jQuery = $ export default $ 这 ...