#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. STM32 ~ 如何从ST网站找到对应的固件库

    ST官方网站改版后,基本上很难搜索到固件库的地址,找了半天才找到固件库的下载地址,通过此方法可以找到其他需要的资源,故记下来方便大家. 下载的网站地址为: Home>Tools and Soft ...

  2. .cxx_destruct crash

    开发过程中遇到 YXTBaseLabelCell .cxx_destruct崩溃,查了下,会在调用类的dealloc方法时调用cxx_destruct,于是看了下代码,找dealloc可能会崩溃的原因 ...

  3. BZOJ 1617 [Usaco2008 Mar]River Crossing渡河问题:dp

    题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1617 题意: Farmer John以及他的N(1 <= N <= 2,500 ...

  4. FFT的常数优化

    卡得一手好常数..学习了..(似乎只对FFT有效) JZOJ 4349 #include <bits/stdc++.h> #define LL long long #define DB l ...

  5. 解决js 运算 精度缺失

    github地址: https://github.com/MikeMcl/big.js

  6. 查看mysql连接情况,以及连接超时时间设置

    查看连接: show processlist;   只展示100个连接 show full processlist;    展示所有连接 查看超时时间: show variables like  '% ...

  7. kitti 数据集解析

    1.KITTI数据集采集平台: KITTI数据采集平台包括2个灰度摄像机,2个彩色摄像机,一个Velodyne 3D激光雷达,4个光学镜头,以及1个GPS导航系统.坐标系转换原理参见click.KIT ...

  8. 关于cuda 环境遇到的问题

    1.error while loading shared libraries: libcudart.so.9.0: cannot open shared object file: No such fi ...

  9. PYTHON 异常处理 一 ASSERT

    assert语句,如果没记错,这个东西在C或者C++里面也有的.属于短小的断言.下面的是来自python help document的说明: Assert statements are a conve ...

  10. git add . 的时候遇到warning: LF will be replaced by CRLF inXXX 解决办法

    $ git add . warning: LF will be replaced by CRLF in shop/Runtime/Cache/86bbc820c9ec1 d314a9c71cf5651 ...