F - Balanced Number
#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的更多相关文章
- [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 ...
- 【HDU 3709】 Balanced Number (数位DP)
Balanced Number Problem Description A balanced number is a non-negative integer that can be balanced ...
- [暑假集训--数位dp]hdu3709 Balanced Number
A balanced number is a non-negative integer that can be balanced if a pivot is placed at some digit. ...
- hdu3709 Balanced Number 树形dp
A balanced number is a non-negative integer that can be balanced if a pivot is placed at some digit. ...
- Balanced Number
Balanced Number Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others) ...
- HDU - 3709 - Balanced Number(数位DP)
链接: https://vjudge.net/problem/HDU-3709 题意: A balanced number is a non-negative integer that can be ...
- HDOJ 3709 Balanced Number
数位DP... Balanced Number Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65535/65535 K (Java ...
- hdu3709 Balanced Number (数位dp+bfs)
Balanced Number Problem Description A balanced number is a non-negative integer that can be balanced ...
随机推荐
- SpringBoot-(4)-Filter的使用
一,Filter Filter功能,它使用户可以改变一个 request和修改一个response. Filter 不是一个servlet,它不能产生一个response,它能够在一个request到 ...
- BAT网络运维常见面试题目总结
BAT常见面试题目总结 Author:Danbo 2015-7-11 TCP/IP详解鸟哥Linux的书网络安全ping的原理make的过程文件有哪些类型各种Linux发行版的区别.有关suid的作用 ...
- cURL范例(包括错误输出和详情输出)
//1.初始化 $ch = curl_init(); //2.设置选项,包括URL curl_setopt($ch, CURLOPT_URL, 'http://www.baidu.com'); cur ...
- Python序列——元组
元组是什么 1 创建元组 2 访问元组中的值 3 更新元组中的元素 4 删除元组中的元素或者元组本身 元组相关操作 内建函数对元组的支持 1 序列类型函数 2 元组内建函数 元组的特殊性 1. 元组是 ...
- LightOJ - 1030 Discovering Gold —— 期望
题目链接:https://vjudge.net/problem/LightOJ-1030 1030 - Discovering Gold PDF (English) Statistics For ...
- nyoj 269 VF
VF 时间限制:1000 ms | 内存限制:65535 KB 链接:NYOJ269 原创在:点击打开链接 题意:1-1000000000之间,各位数字之和等于给定s的数的个数. 每行给出一个数s ...
- [USACO 2008 MAR] 土地购买
[题目链接] https://www.lydsy.com/JudgeOnline/problem.php?id=1597 [算法] 首先将所有土地按长为第一关键字 , 宽为第二关键字排序 显然 , 当 ...
- ab-如何提交post请求
ab -n 1 -c 1 -p post.txt http://***********/ 文件post.txt中存放要post的数据
- gsoap开发webservice
gSOAP编译工具提供了一个SOAP/XML 关于C/C++ 语言的实现,从而让C/C++语言开发web服务或客户端程序的工作变得轻松了很多.绝大多数的C++web服务工具包提供一组API函数类库来处 ...
- MT8735A平台配置MT6630
1. codegen配置 2. ProjectConfig CUSTOM_HAL_ANT = mt6630_ant_m1 CUSTOM_HAL_COMBO = mt6630 MTK_BT_CHIP = ...