hdu3709 Balanced Number 树形dp
to calculate the number of balanced numbers in a given range [x, y].
InputThe input contains multiple test cases. The first line is the total number of cases T (0 < T ≤ 30). For each case, there are two integers separated by a space in a line, x and y. (0 ≤ x ≤ y ≤ 10 18).OutputFor each case, print the number of balanced numbers in the range [x, y] in a line.Sample Input
2
0 9
7604 24324
Sample Output
10
897 题意:一个数,定一个支点,力矩相等为平衡数。
题解:数位dp,f[i][j][k]表示i为,j位为支点,k为当前力矩。
#include<cstring>
#include<cmath>
#include<algorithm>
#include<iostream>
#include<cstdio>
#define ll long long
using namespace std; ll f[][][],l,r;
int a[],n,cnt; ll dfs(int wei,int zd,int lj,bool flag)
{
if (wei==) return lj==;
if (lj<) return ;
if (!flag&&f[wei][zd][lj]!=-) return f[wei][zd][lj];
ll res=;
int ed;
if (flag) ed=a[wei];
else ed=;
for (int i=;i<=ed;i++)
res+=dfs(wei-,zd,lj+(wei-zd)*i,flag&&i==ed);
if (!flag) f[wei][zd][lj]=res;
return res;
}
ll solve(ll x)
{
cnt=;
while(x)
{
a[++cnt]=x%;
x/=;
}
ll ans=;
for (int i=;i<=cnt;i++)
ans+=dfs(cnt,i,,);
return ans-(cnt-);
}
int main()
{
int cas;scanf("%d",&cas);
memset(f,-,sizeof(f));
while(cas--)
{
scanf("%lld%lld",&l,&r);
printf("%lld\n",solve(r)-solve(l-));
}
}
hdu3709 Balanced Number 树形dp的更多相关文章
- HDU3709 Balanced Number —— 数位DP
题目链接:https://vjudge.net/problem/HDU-3709 Balanced Number Time Limit: 10000/5000 MS (Java/Others) ...
- hdu3709 Balanced Number (数位dp+bfs)
Balanced Number Problem Description A balanced number is a non-negative integer that can be balanced ...
- hdu3709 Balanced Number 数位DP
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3709 题目大意就是求给定区间内的平衡数的个数 要明白一点:对于一个给定的数,假设其位数为n,那么可以有 ...
- [HDU3709]Balanced Number
[HDU3709]Balanced Number 试题描述 A balanced number is a non-negative integer that can be balanced if a ...
- HDU3709 Balanced Number (数位dp)
Balanced Number Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & %llu Descript ...
- HDU3709:Balanced Number(数位DP+记忆化DFS)
Problem Description A balanced number is a non-negative integer that can be balanced if a pivot is p ...
- [暑假集训--数位dp]hdu3709 Balanced Number
A balanced number is a non-negative integer that can be balanced if a pivot is placed at some digit. ...
- HDU 3709 Balanced Number (数位DP)
Balanced Number Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others) ...
- HDU3709 Balanced Number 题解 数位DP
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3709 题目大意: 求区间 \([x, y]\) 范围内"平衡数"的数量. 所谓平衡 ...
随机推荐
- Oracle 十大SQL语句
oracle数据库十大SQL语句 操作对象(object) /*创建对象 table,view,procedure,trigger*/ create object object ...
- 阿里Canal框架(数据同步中间件)初步实践
最近在工作中需要处理一些大数据量同步的场景,正好运用到了canal这款数据库中间件,因此特意花了点时间来进行该中间件的的学习和总结. 背景介绍 早期,阿里巴巴B2B公司因为存在杭州和美国双机房部署,存 ...
- 前端之HTML语法及常用标签
html语法: 1.常规标记: <标记 属性=“属性值” 属性=“属性值”></标记>: 2.空标记: <标记 属性=“属性值” 属性=“属性值”/> 注意事项: ...
- poj1724 ROADS
题意: N个城市,编号1到N.城市间有R条单向道路.每条道路连接两个城市,有长度和过路费两个属性.Bob只有K块钱,他想从城市1走到城市N.问最短共需要走多长的路.如果到不了N,输出-12<=N ...
- new操作符具体干了什么
function Func(){ }; var newFunc=new Func (); new共经过了4个阶段 1.创建一个空对象 var obj=new Object(); 2.设置原型链 把 o ...
- iOS 随笔 允许所有不安全网络访问项目
允许任意请求访问app App Transport Security Settings -> Allow Arbitrary Loads YES
- std::map插入已存在的key时,key对应的内容不会被更新
std::map插入已存在的key时,key对应的内容不会被更新,如果不知道这一点,可能会造成运行结果与预期的不一致 “Because element keys in a map are unique ...
- mysql use index() 优化查询
mysql use index() 优化查询 FORCE INDEX/IGNORE INDEX 的语法: SELECT *** FROM TABLE [{USE|IGNORE|FORCE} INDEX ...
- 11gR2集群件任务角色分离(Job Role Separation)简介
从11gR2版本开始,Oracle推荐使用不同的操作系统用户安装GI和数据库软件,例如:使用grid用户安装GI,使用Oracle用户安装数据库软件.当然,用户还是可以使用Oracle用户安装G ...
- python_使用qrcode生成二维码
1.功能 使用qrcode生成二维码 2.代码 #生成二维码: import qrcode #根据url生成二维码 def qrcodeWithUrl(url): img = qrcode.make( ...