Hdu 3709 Balanced Number
来源:互联网 发布:php linux 删除文件夹 编辑:程序博客网 时间:2024/05/21 05:21
题目:http://acm.hdu.edu.cn/showproblem.php?pid=3709
思路:平衡数。枚举平衡位置,记忆化搜索的方式记录已有的值。加剪枝,排除掉重复的0。
#include <iostream>#include <stdio.h>#include <stdlib.h>#include <string.h>#include <math.h>#include <map>#include <queue>#include <algorithm>using namespace std;#define LL long long#define Maxn 20LL dp[Maxn][Maxn][2005];int digit[Maxn];LL dfs(int pos,int pivot,int pre,bool limit){ if(pos<=0) return pre == 0; if(pre<0) return 0; if(!limit && dp[pos][pivot][pre]!=-1) return dp[pos][pivot][pre]; int end = limit ? digit[pos] : 9; LL ans = 0; for(int i=0;i<=end;i++) { ans += dfs(pos-1,pivot,pre + i*(pos-pivot),limit && (i == end)); } if(!limit) dp[pos][pivot][pre] = ans; return ans;}LL calc(LL a){ if(a<0) return 0; int len = 0; LL ans = 0; while(a>0) { digit[++len] = a%10; a/=10; } for(int i=1;i<=len;i++) { ans += dfs(len,i,0,1); } ans = ans - len + 1; return ans;}int main(){ int t; LL x,y; scanf(" %d",&t); memset(dp,-1,sizeof(dp)); while(t--) { scanf(" %I64d %I64d",&x,&y); printf("%I64d\n",calc(y) - calc(x-1) ); } return 0;}
0 0
- HDU 3709 Balanced Number
- hdu 3709 Balanced Number
- HDU 3709 Balanced Number
- HDU-3709 Balanced Number
- HDU 3709 Balanced Number
- HDU 3709 Balanced Number
- HDU 3709 Balanced Number
- HDU 3709 Balanced Number
- HDU 3709 Balanced Number
- Hdu 3709 Balanced Number
- Hdu 3709 Balanced Number
- HDU 3709 Balanced Number
- hdu 3709 Balanced Number
- HDU 3709 Balanced Number
- HDU 3709 Balanced Number(数位DP)
- 数位dp HDU 3709 Balanced Number
- hdu 3709 Balanced Number (数位dp)
- hdu 3709 Balanced Number(数位dp)
- compile与link区别
- leetCode练习(35)
- 树莓派之网络设置
- 字符串反转
- Struts2自学入门(五)——OGNL
- Hdu 3709 Balanced Number
- 单例模式
- 杂记 (3) —— C and linux
- Codeforces 50A(往矩形里填多米诺骨牌)
- 商务旅行_codevs1036_lca
- bzoj 2982: combination lucas定理+乘法逆元
- SPI通信总线-51
- java 集合小记1
- Executor并发性能对比