hdu3709】的更多相关文章

[HDU3709]Balanced Number 试题描述 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…
http://acm.hdu.edu.cn/showproblem.php?pid=3709 (题目链接) 题意 求范围${[a,b]}$之间的平衡数的个数,所谓平衡数就是以某一位为支点,两侧的力矩相等. Solution 数位dp记忆化搜索. 一般的数位dp记忆化搜索一定是从高位往低位搜索,传递2个参数:pos,当前dp的位置:lim是否有上限.如果没有上限就可以利用记忆化的${f}$来返回值了. 这道题的话就是枚举支点,然后从高位往低位搜索过去,复杂度大概是${O(20*10*2000)}$…
题目链接:https://vjudge.net/problem/HDU-3709 Balanced Number Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others)Total Submission(s): 6615    Accepted Submission(s): 3174 Problem Description A balanced number is a non-nega…
枚举+数位dp 注意处理数字为0和1的情况. #include <cstdio> #include <cstring> using namespace std; #define D(x) ; long long n; int f[MAX_DIGIT]; **]; int pivot; int to_digits(long long a) { ; ) { f[++ret] = a % ; a /= ; } return ret; } long long dfs(int digit,…
Balanced Number 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…
 Balanced Number Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu 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 wi…
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 nu…
求区间[l,r]内有多少个数的满足:   选一个位为中点,是的左边的数到该位的距离等于右边的位到该位的距离. 比如4139  选择3位中点, 那么左边的距离是 4 * 2 + 1 * 1 , 右边的距离是9 * 1 想了半天,想到了枚举哪一位作为中点, 然后进行数位dp, 但是样例错了, 忽然想到会重复啊,就百度了一下 原来只有0在枚举中点时会重复,其他的数有且只有一个中点是的左边的距离等于右边的距离 所以只要最后ans-len+1即可 #include <functional> #inclu…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3709 题目大意就是求给定区间内的平衡数的个数 要明白一点:对于一个给定的数,假设其位数为n,那么可以有n个不同的位作为支点,但每次只能有一个支点 定义dp[len][pos][k],len表示当前还需处理的位数,pos表示当前的所选的支点的位置,k表示计算到当前的力矩之和(即从最高位到第len+1位) 容易知道如果在某一个len>1的位置k已经小于0,那么就可以直接剪枝 代码如下 : #includ…
枚举fix所在的位置loc即可,然后数位dp即可 这题要注意一种特殊情况,就是所有位都是0的时候对于每个fix都是成立的 /* dp[i][j][k]表示前i位确定了平衡点在第j位,前i位和为k fix需要在开始dfs前就预先确定下来 */ #include<bits/stdc++.h> using namespace std; #define ll long long ll dp[][][],a[]; ll dfs(ll pos,ll fix,ll sum,ll lim){ )?:; );…