博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
hdu 3709 数字dp(小思)
阅读量:6073 次
发布时间:2019-06-20

本文共 1986 字,大约阅读时间需要 6 分钟。

Problem Description
A balanced number is a non-negative integer that can be balanced if a pivot is placed at some digit. More specifically, imagine each digit as a box with weight indicated by the digit. When a pivot is placed at some digit of the number, the distance from a digit to the pivot is the offset between it and the pivot. Then the torques of left part and right part can be calculated. It is balanced if they are the same. A balanced number must be balanced with the pivot at some of its digits. For example, 4139 is a balanced number with pivot fixed at 3. The torqueses are 4*2 + 1*1 = 9 and 9*1 = 9, for left part and right part, respectively. It's your job
to calculate the number of balanced numbers in a given range [x, y].
 

Input
The 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).
 

Output
For 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
/**hdu 3709   数位dp(小思维)解题思路:有一个非常好的转化技巧,不然会超时。搜索的时候初始值定为f(x),然后最后和0比較。不要搜f(i) 和f(x)比較*/#include 
#include
#include
#include
using namespace std;typedef long long LL ;LL dp[25][25][2000],l,r;int bit[25];LL dfs(int len,int pos,int sum,int flag){ if(len<0) { //printf("%d %d>>>>\n",suml,sumr); return sum==0; } if(flag==0&&dp[len][pos][sum]!=-1) return dp[len][pos][sum]; int end=flag?bit[len]:9; LL ans=0; for(int i=0;i<=end;i++) { //printf("len-1:%d\n",len-1); ans+=dfs(len-1,pos,(sum+(len-pos)*i),flag&&i==end); } if(flag==0) { dp[len][pos][sum]=ans; } return ans;}LL solve(LL n){ if(n==-1)return 0; int len=0; while(n) { bit[len++]=n%10; n/=10; } LL ans=0; for(int i=0;i

版权声明:本文博客原创文章,博客,未经同意,不得转载。

你可能感兴趣的文章
Sql与C#中日期格式转换总结
查看>>
iOS开发流程总结
查看>>
hadoop datanode 启动出错
查看>>
js颜色拾取器
查看>>
IDEA使用(1)intellIJ idea 配置 svn
查看>>
Thread Safety in Java(java中的线程安全)
查看>>
WPF 降低.net framework到4.0
查看>>
数据管理DMS 全量SQL诊断:你的SQL是健康的蓝色,还是危险的红色?
查看>>
搭建一个通用的脚手架
查看>>
开年巨制!千人千面回放技术让你“看到”Flutter用户侧问题
查看>>
开源磁盘加密软件VeraCrypt教程
查看>>
本地vs云:大数据厮杀的最终幸存者会是谁?
查看>>
阿里云公共镜像、自定义镜像、共享镜像和镜像市场的区别 ...
查看>>
shadowtunnel v1.7 发布:新增上级负载均衡支持独立密码
查看>>
Java线程:什么是线程
查看>>
mysql5.7 创建一个超级管理员
查看>>
【框架整合】Maven-SpringMVC3.X+Spring3.X+MyBatis3-日志、JSON解析、表关联查询等均已配置好...
查看>>
要想成为高级Java程序员需要具备哪些知识呢?
查看>>
带着问题去学习--Nginx配置解析(一)
查看>>
onix-文件系统
查看>>