#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <string>
#include <map>
#include <cmath>
#include <vector> #define Faster ios::sync_with_stdio(false),cin.tie(0)
#define Read freopen("in.txt","r",stdin),freopen("out.txt","w",stdout)
#define Close fclose(stdin),fclose(stdout)
const int maxn = 1e4 + ;
using namespace std;
const int MOD = 1e9+;
typedef long long ll; ll dp[][][];
int a[]; ll dfs(int pos, int cut, int sum, bool limit){
if (pos == -) return sum?:; //sum为0的时候说明是平衡的
if (sum < ) return ; //sum < 0 就肯定不平衡了返回0
if(!limit && dp[pos][cut][sum] != -)
return dp[pos][cut][sum];
int up = limit?a[pos]:;
ll ans = ;
for(int i = ; i <= up;i++){
ans += dfs(pos-, cut, sum + (pos-cut)*i, limit && a[pos] == i);
}
if(!limit)
dp[pos][cut][sum] = ans;
return ans;
} ll solve(ll x){
int pos = ;
while(x){
a[pos++] = x%;
x /= ;
}
ll ans = ;
for(int i = ;i < pos;i++){
ans += dfs(pos-, i, , true);
}
return ans - pos + ;
//因为0多加了(pos - 1)次
} int main(){
Faster;
int t;
cin >> t;
memset(dp, -, sizeof(dp));
while(t--){
ll l, r;
cin >> l >> r;
ll ans = solve(r) - solve(l-);
cout << ans << endl;
}
return ;
}

F - Balanced Number的更多相关文章

  1. [HDU3709]Balanced Number

    [HDU3709]Balanced Number 试题描述 A balanced number is a non-negative integer that can be balanced if a ...

  2. HDU3709 Balanced Number (数位dp)

     Balanced Number Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu Descript ...

  3. 【HDU 3709】 Balanced Number (数位DP)

    Balanced Number Problem Description A balanced number is a non-negative integer that can be balanced ...

  4. [暑假集训--数位dp]hdu3709 Balanced Number

    A balanced number is a non-negative integer that can be balanced if a pivot is placed at some digit. ...

  5. hdu3709 Balanced Number 树形dp

    A balanced number is a non-negative integer that can be balanced if a pivot is placed at some digit. ...

  6. Balanced Number

    Balanced Number Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others) ...

  7. HDU - 3709 - Balanced Number(数位DP)

    链接: https://vjudge.net/problem/HDU-3709 题意: A balanced number is a non-negative integer that can be ...

  8. HDOJ 3709 Balanced Number

    数位DP... Balanced Number Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java ...

  9. hdu3709 Balanced Number (数位dp+bfs)

    Balanced Number Problem Description A balanced number is a non-negative integer that can be balanced ...

随机推荐

  1. 无法启动FTP站点,服务目前停止

    在本地搭建了一个FTP服务器(windows搭建FTP服务器实战),再启动的时候提示错误: 错误提示信息: 根据提示可以查出问题原因:FTP服务没有开启 启动服务,再次重启站点服务.一切OK. 亲测好 ...

  2. appium(7)-Automating mobile gestures

    While the Selenium WebDriver spec has support for certain kinds of mobile interaction, its parameter ...

  3. PHP Json函数不能处理中文的解决办法

    PHP5.2 新增的 json 功能是非常受欢迎的,但是经过测试发现,json_encode 对中文的处理是有问题的: 不能处理GB编码,所有的GB编码都会替换成空字符: utf8编码的中文被编码成u ...

  4. Android BLE 总结-源码篇(BluetoothLeAdvertiser)

    在做Android BLE的应用程序时,我们发出广播数据是调用BluetoothLeAdvertiser的startAdvertising方法,如下所示: mBluetoothLeAdvertiser ...

  5. c#设置系统时间后不起作用

    网上设置系统时间的代码很多,但是会出现设置后没有作用的问题 遇到以上问题可以按照如下办法解决 1.项目--属性--安全性--勾选启用ClickOne安全设置,如下图所示: 2.打开app.manife ...

  6. DB2删除表分区

    近日,由于部门数据库读库空间过小,提出删除掉两个月之前日志表的分区(数据库分区是按时间月分区),记述如下: 上网搜索资料发现删除表分区大概分这么几步: 1.查询需要删除掉的分区: select t.D ...

  7. tomcat 启动增加参数

    linux: JAVA_OPTS="$JAVA_OPTS  -Dconfig.type=inte2 -Xms2048m -Xmx2048m -XX:PermSize=128m -XX:Max ...

  8. CodeForces - 597C:Subsequences (主席树+DP)

    For the given sequence with n different elements find the number of increasing subsequences with k + ...

  9. Tomcat 安装之后,双击Tomcat.exe,无法运行成功,怎么办?

    Log形式多种多样,有的时候跟下面一样: 首先的解决方案就是:修改server.xml中所有的端口,因为不只8080端口可能被占用! 我在出问题的时候就修改8080端口.结果死活运行不了,纠结一些时间 ...

  10. JavaScript-Tool-导向:jquery.steps-un

    ylbtech-JavaScript-Tool-导向:jquery.steps 1.返回顶部   2.返回顶部   3.返回顶部   4.返回顶部   5.返回顶部 0. http://www.jqu ...