[暑假集训--数位dp]hdu3709 Balanced Number
to calculate the number of balanced numbers in a given range [x, y].
0 9
7604 24324
897
问有多少个数字是“平衡”的,平衡就是取个参考点,左边的数字*距离=右边的数字*距离,4139以3为参考点就是4*2+1*1==9*1
一个数字的参考点唯一。
枚举参考点是第几位,然后对于每一个参考点的位数k,分别跑数位dp,记一下参考点位置,左边的力矩,有没有前导零。在参考点右边的时候直接在力矩上面减即可。
#include<cstdio>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<queue>
#include<deque>
#include<set>
#include<map>
#include<ctime>
#define int long long
#define LL long long
#define inf 0x7ffffff
#define pa pair<int,int>
#define mkp(a,b) make_pair(a,b)
#define pi 3.1415926535897932384626433832795028841971
using namespace std;
inline LL read()
{
LL x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
LL n,len,l,r;
LL f[][][][];
int d[];
int zhan[],top;
inline LL dfs(int now,int p,int M,int lead,int fp)
{
if (now==)return !M;
if (!fp&&f[now][p][M][lead]!=-)return f[now][p][M][lead];
LL ans=,mx=fp?d[now-]:;
for (int i=;i<=mx;i++)
{
int delta=i*(now--p);
if (M+delta<)break;
if (now-==p&&i==&&lead&&now-!=)continue;
ans+=dfs(now-,p,M+delta,lead&&i==&&now-!=,fp&&i==mx);
}
if (!fp)f[now][p][M][lead]=ans;
return ans;
}
inline LL calc(LL x)
{
if (x==-)return ;
if (x==)return ;
LL xxx=x;
len=;
while (xxx)
{
d[++len]=xxx%;
xxx/=;
}
LL sum=;
for (int i=;i<=len;i++)
{
for (int j=;j<=d[len];j++)
if (!(j==&&i==len)||len==)
{
sum+=dfs(len,i,j*(len-i),j==&&len!=,j==d[len]);
}
}
return sum;
}
main()
{
int T=read(),cnt=;
memset(f,-,sizeof(f));
while (T--)
{
l=read();
r=read();
if (r<l)swap(l,r);
printf("%lld\n",calc(r)-calc(l-));
}
}
hdu 3709
[暑假集训--数位dp]hdu3709 Balanced Number的更多相关文章
- [暑假集训--数位dp]hdu5787 K-wolf Number
Alice thinks an integer x is a K-wolf number, if every K adjacent digits in decimal representation o ...
- [暑假集训--数位dp]hdu5898 odd-even number
For a number,if the length of continuous odd digits is even and the length of continuous even digits ...
- [暑假集训--数位dp]LightOj1205 Palindromic Numbers
A palindromic number or numeral palindrome is a 'symmetrical' number like 16461 that remains the sam ...
- [暑假集训--数位dp]hdu3555 Bomb
The counter-terrorists found a time bomb in the dust. But this time the terrorists improve on the ti ...
- [暑假集训--数位dp]hdu3652 B-number
A wqb-number, or B-number for short, is a non-negative integer whose decimal form contains the sub- ...
- [暑假集训--数位dp]hdu2089 不要62
杭州人称那些傻乎乎粘嗒嗒的人为62(音:laoer).杭州交通管理局经常会扩充一些的士车牌照,新近出来一个好消息,以后上牌照,不再含有不吉利的数字了,这样一来,就可以消除个别的士司机和乘客的心理障碍, ...
- [暑假集训--数位dp]LightOJ1140 How Many Zeroes?
Jimmy writes down the decimal representations of all natural numbers between and including m and n, ...
- [暑假集训--数位dp]LightOj1032 Fast Bit Calculations
A bit is a binary digit, taking a logical value of either 1 or 0 (also referred to as "true&quo ...
- [暑假集训--数位dp]cf55D Beautiful numbers
Volodya is an odd boy and his taste is strange as well. It seems to him that a positive integer numb ...
随机推荐
- C Library - <limits.h>
Introduction The limits.h header determines various properties of the various variable types. The ma ...
- sql 经典加强巩固练习题
由于本人需要加强巩固一下数据库知识,就搜罗了一些题目来练习,感觉不错,故分享一下资源难度层度依次上升这50道里面自认为应该没有太多错误,而且尽可能使用了最简单或是最直接的查询,有多种不相上下解法的题目 ...
- 状态压缩dp 状压dp 详解
说到状压dp,一般和二进制少不了关系(还常和博弈论结合起来考,这个坑我挖了还没填qwq),二进制是个好东西啊,所以二进制的各种运算是前置知识,不了解的话走下面链接进百度百科 https://baike ...
- 【Git版本控制】GitHub上fork项目和clone项目的区别
fork:在github页面,点击fork按钮,将别人的仓库复制一份到自己的仓库. clone:直接将github中的仓库克隆到自己本地电脑中 问题1:pull request的作用 比如在仓库的主人 ...
- mysql命令行复制数据库
为了方便快速复制一个数据库,可以用以下命令将db1数据库的数据以及表结构复制到newdb数据库创建新的数据库#mysql -u root -p123456 mysql>CREATE DATABA ...
- Centos7系统下安装Docker
1.确定你的Linux系统是Centos7 命令:cat /etc/redhat-release 2.yum安装gcc相关 1.配置好Centos7能上外网. 2.yum -y install gcc ...
- PHP 代码优化建议
1.尽量静态化: 如果一个方法能被静态,那就声明它为静态的,速度可提高1/4,甚至我测试的时候,这个提高了近三倍.当然了,这个测试方法需要在十万级以上次执行,效果才明显.其实静态方法和非静态方法的效率 ...
- 【laravel】Laravel 5 TokenMismatchException on PHP 5.6.9
When I realized this was only happening in IE and Chrome, but not Firefox, it led me to the fix. The ...
- Head First Python (二)
if...else... 1 movies = ["The Holy Grail",1975,"Terry Jones & Terry Gilliam" ...
- 在windows7 32ibt安装MongoDB数据库的方法及连接失败解决方案
参考 https://www.cnblogs.com/cnblogs-jcy/p/6734889.html http://yunkus.com/mongodb-install-config-in-wi ...