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]\) 范围内"平衡数"的数量. 所谓平衡 ...
随机推荐
- 响应式布局 max-device-width 与 max-width 的区别
闲来没事,研究了一下多屏适配和响应式布局的 CSS. 第一种写法 @media screen and (max-device-width: 320px) { } @media screen and ( ...
- Tcl介绍和基础语法
Tcl的背景 Tcl(读作tickle)诞生于80年代的加州大学伯克利分校,作为一种简单高效可移植性好的脚本语言,目前已经广泛应用在几乎所有的EDA工具中.Tcl 的最大特点就是其语法格式极其简单,采 ...
- Understanding Scroll Views 深入理解 scroll view 读书笔记
Understanding Scroll Views 深入理解 scroll view 读书笔记 It may be hard to believe, but a UIScrollView is ...
- Mac上面不能安装Homebrew
这个stackoverflow的答案解决了我的问题: http://stackoverflow.com/questions/18039029/mac-can-t-install-homebrew 问题 ...
- 为什么ABAP整型的1转成string之后,后面会多个空格
有同事问这个问题:lv_s是从int4转过来的,长度为2,和硬编码的lv_s2(长度为1)相比,后面多了个空格. 为什么?查SAP ABAP的编程帮助F1 help. 帮助文档说的很清楚了:如果赋值操 ...
- Wikidata和SparQL简介
知识库 数据库(Database)和SQL,相信我们大部分人都非常非常熟悉.但是“知识库”可能知道的人就要相对少一些. 知识库是一个相对比较新的概念,它其实是一堆“三元组”(类似于主-谓-宾)的组合, ...
- zabbix利用微信报警
一.背景介绍 报警的方式有很多种,比如常用的邮件报警,短信,微信等.那这篇文章主要是实现微信报警. 值得注意的是,之前使用微信企业公众号,现在微信企业公众号更新成企业微信了.所以直接注册企业微信,进入 ...
- 关于sigleton模式
单例模式的要点有三个:一是某个类只能有一个实例:二是它必须自行创建这个实例:三是它必须自行向整个系统提供这个实例. 从具体实现角度来说,就是以下三点:一是单例模式的类只提供私有的构造函数,二是类定义中 ...
- 浏览器title失去焦点时改变title
document.addEventListener('visibilitychange', function() { var isHidden = document.hidden; if (isHid ...
- pooling需要注意的一个地方
max pooling 在不同的 depth 上是分开执行的,且不需要参数控制.也就是说,pooling之后,feature map的维度不会改变