POJ3252Round Numbers(数位dp)
题意
给出区间$[A, B]$,求出区间内的数转成二进制后$0$比$1$多的数的个数
$1 \leqslant A, B \leqslant 2,000,000,000$
Sol
比较zz的数位dp
直接在二进制下dp就好
$f[i][ze][on]$表示第$i$位,填了$ze$个$0$,$on$个1的方案数
#include<cstdio>
#include<cstring>
#include<iostream>
// #include<map>
using namespace std;
#define LL long long
const LL MAXN = ;
LL A, B;
LL num[MAXN], tot, f[MAXN][MAXN][MAXN];
LL dfs(LL x, bool lim, LL ze, LL on) {
if(x == ) return
(ze != -) && (on != -) && (ze >= on);
if(!lim && f[x][ze][on]) return f[x][ze][on];
LL ans = ;
for(LL i = ; i <= (lim ? num[x] : ); i++) {
if(i == ) ans += dfs(x - , lim && (i == num[x]), ze == - ? : ze + , on);
else {
if(on == -) ans += dfs(x - , lim && (i == num[x]), , );
else ans += dfs(x - , lim && (i == num[x]), ze, on + );
}
}
if(!lim) f[x][ze][on] = ans;
return ans;
}
LL solve(LL x) {
tot = ;
while(x) num[++tot] = x % , x >>= ;
return dfs(tot, , -, -);
}
int main() {
cin >> A >> B;
cout << solve(B) - solve(A - );
return ;
}
/*
1234 4444
2
*/
POJ3252Round Numbers(数位dp)的更多相关文章
- 2018 ACM 国际大学生程序设计竞赛上海大都会赛重现赛 J Beautiful Numbers (数位DP)
2018 ACM 国际大学生程序设计竞赛上海大都会赛重现赛 J Beautiful Numbers (数位DP) 链接:https://ac.nowcoder.com/acm/contest/163/ ...
- codeforces 55D - Beautiful numbers(数位DP+离散化)
D. Beautiful numbers time limit per test 4 seconds memory limit per test 256 megabytes input standar ...
- Codeforces Beta Round #51 D. Beautiful numbers 数位dp
D. Beautiful numbers Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/55/p ...
- poj 3252 Round Numbers(数位dp 处理前导零)
Description The cows, as you know, have no fingers or thumbs and thus are unable to play Scissors, P ...
- uva 10712 - Count the Numbers(数位dp)
题目链接:uva 10712 - Count the Numbers 题目大意:给出n,a.b.问说在a到b之间有多少个n. 解题思路:数位dp.dp[i][j][x][y]表示第i位为j的时候.x是 ...
- SPOJ BALNUM - Balanced Numbers - [数位DP][状态压缩]
题目链接:http://www.spoj.com/problems/BALNUM/en/ Time limit: 0.123s Source limit: 50000B Memory limit: 1 ...
- SPOJ10606 BALNUM - Balanced Numbers(数位DP+状压)
Balanced numbers have been used by mathematicians for centuries. A positive integer is considered a ...
- Codeforces 914 C. Travelling Salesman and Special Numbers (数位DP)
题目链接:Travelling Salesman and Special Numbers 题意: 给出一个二进制数n,每次操作可以将这个数变为其二进制数位上所有1的和(3->2 ; 7-> ...
- Educational Codeforces Round 8 D. Magic Numbers 数位DP
D. Magic Numbers 题目连接: http://www.codeforces.com/contest/628/problem/D Description Consider the deci ...
随机推荐
- C# 架构模式
单例模式 (Singleton) 单例讲的是当一个类被初次调用时,会产生一个类的实例, 而这个类的实例会贯穿程序的整个生命周期.单例提供了一个全局.唯一的实例. 步骤:1.让类自己创建一个实例:2.提 ...
- CentOS虚拟机通过主机网络上网
0 环境简介 环境如下: (1)宿主机为WIN7系统,连接内网,同时通过网关服务器上外网: (2)虚拟机为VMWare12下的CentOS7系统. 宿主机通过WIFI方式上外网的配置方法,参考本人另一 ...
- POJ-3262
Protecting the Flowers Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 7923 Accepted: ...
- java之二叉树--未完待续
参考http://how2j.cn/k/collection/collection-tree/476.html#nowhere 二叉树概念 二叉树由各种节点组成二叉树特点:每个节点都可以有左子节点,右 ...
- AngularJS 2.0 学习
前提: 下载和安装node.js 和 npm. https://nodejs.org/en/download/ npm安装 需要自己google 安装好之后,可以在cmd窗口中查看安装的版本 node ...
- python中出现 IndentationError:unindent does not match any outer indentation level
python中出现IndentationError:unindent does not match any outer indentation level 今天在网上copy的一段代码,代码很简单,每 ...
- 结对项目-ExamGeneration-四则运算试题生成与计算程序
目录 ExamGeneration 进展 功能 调用示例 PSP表格 结对分工 功能模块详解 Chernobyl: -Gaveu: 运行测试 -Gaveu: Chernobyl: 项目总结与反思 Ch ...
- Untiy ShaderLab 随手记录
最基本形式 (先不考虑Fog) Shader "Nafio/TUnlit"{ Properties { _MainTex("TT",2D) = "wh ...
- python 之 序列化与反序列化、os模块
6.6 序列化与反序列化 特殊的字符串 , 只有:int / str / list / dict 最外层必须是列表或字典,如果包含字符串,必须是双引号"". 序列化:将Python ...
- SpringMVC重定向传递参数
在SpringMVC的一个controller中要把参数传到页面,只要配置视图解析器,把参数添加到Model中,在页面用el表达式就可以取到.但是,这样使用的是forward方式,浏览器的地址栏是不变 ...