hdu3709(数位dp)】的更多相关文章

枚举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){ )?:; );…
 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…
求区间[l,r]内有多少个数的满足:   选一个位为中点,是的左边的数到该位的距离等于右边的位到该位的距离. 比如4139  选择3位中点, 那么左边的距离是 4 * 2 + 1 * 1 , 右边的距离是9 * 1 想了半天,想到了枚举哪一位作为中点, 然后进行数位dp, 但是样例错了, 忽然想到会重复啊,就百度了一下 原来只有0在枚举中点时会重复,其他的数有且只有一个中点是的左边的距离等于右边的距离 所以只要最后ans-len+1即可 #include <functional> #inclu…
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 f…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3709 题目大意: 求区间 \([x, y]\) 范围内"平衡数"的数量. 所谓平衡数是指:以某一位为支点,它左边的所有位的数乘以它到支点的距离之和等于它右边的所有位的数乘以它到支点的距离之和. 比如, \(4139\) 是平衡数,因为以 \(3\) 为支点, 左边的每一位数与距离的乘积和为 \(4 \times 2 + 1 \times 1 = 9\): 右边的每一位数与距离的乘积和为 \…
因为这几天写的几道数位DP大多都太水..而且也确实没什么好讲所以就扔到一起了. [hdu4772]Good Numbers 要求统计区间内 各位数之和能被10整除 的数的个数. 练手,f[i][j][k]表示i位的数,以j开头,各位数之和取模10的结果为k,的方案数. #include<cstdio> #include<iostream> #include<cstring> #define ll long long using namespace std; int i,…
BZOJ  1026: [SCOI2009]windy数: 题目链接: http://www.lydsy.com/JudgeOnline/problem.php?id=1026           dp[11][11][2]:dep,pre,f 要求的性质就是相邻数字差至少是2.          递归函数的状态设计如下dep,pre,f,分别表示已经枚举到第dep位,他的前一位(更高的位)是pre,f表示大小关系是否已经确定. #include<bits/stdc++.h> using na…
[BZOJ1662][Usaco2006 Nov]Round Numbers 圆环数 Description 正如你所知,奶牛们没有手指以至于不能玩"石头剪刀布"来任意地决定例如谁先挤奶的顺序.她们甚至也不能通过仍硬币的方式. 所以她们通过"round number"竞赛的方式.第一头牛选取一个整数,小于20亿.第二头牛也这样选取一个整数.如果这两个数都是 "round numbers",那么第一头牛获胜,否则第二头牛获胜. 如果一个正整数N的二…
基础的数位dp 但是ce了一发,(abs难道不是cmath里的吗?改成bits/stdc++.h就过了) #include <bits/stdc++.h> using namespace std; int a,b,len; ][],dight[]; int solve(int x) { ) ; ; ;x>;x/=) dight[++len]=x%; ;i<=dight[len]-;i++) ans+=dp[len][i]; ;i>;i--) ;j<=;j++) ans+…
辣鸡军训毁我青春!!! 因为在军训,导致很长时间都只能看书yy题目,而不能溜到机房鏼题 于是在猫大的帮助下我发现这道习题是数位dp 然后想起之前讲dp的时候一直在补作业所以没怎么写,然后就试了试 果然dp的代码比数据结构题短到不知道哪里去了,而且1A,爽啊 #include <cstdio> ,T,n,m; ][][]; int main() { for(scanf("%d",&T);t<=T;t++) { scanf("%d%d",&am…