HDU5179 beautiful number 数位DP
来源:互联网 发布:亚伟速录软件下载6.0 编辑:程序博客网 时间:2024/05/10 22:15
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5179
题目大意:找出[l,r]中高位数字可以整除低位且不小于低位数字的数的个数。
实现代码如下:
#include <cstdio>#include <cstring>using namespace std;int dp[25][25][3];int dig[25],len;int dfs(int pos,int pre,int lim,int z){ if(pos<=0) return 1; if(!lim&&dp[pos][pre][z]!=-1) return dp[pos][pre][z]; int num=lim?dig[pos]:9; int ans=0,i=0; if(z==0) i=1; for(;i<=num;i++) { if(pre==0) ans+=dfs(pos-1,i,lim&&(i==num),z&&(i==0)); else { if( pre>=i && pre%i==0) ans+=dfs(pos-1,i,lim&&(i==num),z&&(i==0)); } } if(!lim) dp[pos][pre][z]=ans; return ans;}int count(int x){ len=0; while(x) { dig[++len]=x%10; x/=10; } memset(dp,-1,sizeof(dp)); return dfs(len,0,1,1);}int main(){ int t,l,r; scanf("%d",&t); while(t--) { scanf("%d%d",&l,&r); printf("%d\n",count(r)-count(l-1)); } return 0;}
0 0
- HDU5179 beautiful number 数位DP
- HDU5179 beautiful number(数位DP)
- hdu5179---beautiful number
- hdu5179 beautiful number
- hdu5179 数位DP
- hdu5179 数位dp
- FZU 2070 - Beautiful number 数位DP..
- hdu 5179 beautiful number (数位dp)
- CF-55D-数位DP-Beautiful Number
- hdu 5179 beautiful number【数位dp】
- 【CodeForces 55D】Beautiful number 数位DP
- HDU 5179 beautiful number 数位DP(水)
- beautiful number(HDU 5179 数位DP)
- hdu 5179 beautiful number (数位DP)
- BC#31.1002beautiful number——数位DP/暴力
- hdu 5179 beautiful number(打表,数位DP)
- Codeforces 55D Beautiful Number (数位dp)
- CF 55D beautiful number(数位dp)
- 开发规范V1.0
- C语言总结错误
- [LeetCode]Reverse Bits
- 1022. D进制的A+B (20)
- 《啊哈!算法》第8章详解
- HDU5179 beautiful number 数位DP
- Mybatis系列目录篇
- Matlab的imfilter函数用法
- opencv中Mat的使用与存取
- 去哪儿MySQL开发规范
- javascript之DOM操作
- 简单Dialog
- 数据结构例程——二叉树遍历的递归算法
- introsort源码