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 ...
随机推荐
- BLE Mesh网络协议综述
0 引言 自2012年蓝牙4.0规范推出之后,全新的蓝牙低功耗(BLE)技术由于其极低的运行和待机功耗.低成本和跨厂商互操作性,3 ms低延迟.AES-128加密等诸多特色,可以用于计步器.心律监视器 ...
- phpmyadmin数据库密码的设置
用phpMyAdmin修改mysql数据库密码 修改mysql数据库密码方法有很多,这里向大家演示一种比较简单的方法,利用phpMyAdmin修改. 工具/原料 phpMyAdmin软件 my ...
- 整理出来的一个windows关机、锁定、重启、注销 API调用
using System.Runtime.InteropServices; namespace HookDemo { class WindowsExit { [StructLayout(LayoutK ...
- exsi thick convert to thin
http://gaoming.blog.51cto.com/822334/1176139
- Uncommon Words from Two Sentences
https://leetcode.com/problems/uncommon-words-from-two-sentences We are given two sentences A and B. ...
- 《SpringBoot揭秘 快速构建微服务体系》读后感(五)
应用日志和spring-boot-starter-logging 快速web应用开发与spring-boot-starter-web 1.项目结构层面的约定
- 【机器学习】分类算法——Logistic回归
一.LR分类器(Logistic Regression Classifier) 在分类情形下,经过学习后的LR分类器是一组权值w0,w1, -, wn,当测试样本的数据输入时,这组权值与测试数据按照线 ...
- JavaEE 企业级分布式高级架构师课程
总目录: 第一课(2018.7.10) 01 mybatis框架整体概况(2018.7.10)-
- 安装完SAP后BASIS的配置流程
安装完SAP后BASIS配置流程 安装完SAP后,配置流程. 1.升级kernel. 2.TCD SLICENSE: License Administration install > Syste ...
- exporting
exporting: { buttons: { contextButton: { menuItems: [{ text: '导出png图片 100宽度', onclick: function () { ...