HDU5179 beautiful number(数位DP)
来源:互联网 发布:视频大数据应用领域 编辑:程序博客网 时间:2024/05/21 04:41
beautiful number
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 607 Accepted Submission(s): 379
Problem Description
Let A=∑ni=1ai∗10n−i(1≤ai≤9)(n is the number of A’s digits). We call A as “beautiful number” if and only if a[i]≥a[i+1] when 1≤i< n and a[i] mod a[j]=0 when 1≤i≤n,i< j≤n(Such as 931 is a “beautiful number” while 87 isn’t).
Could you tell me the number of “beautiful number” in the interval [L,R](including L and R)?
Input
The fist line contains a single integer T(about 100), indicating the number of cases.
Each test case begins with two integers L,R(1≤L≤R≤109).
Output
For each case, output an integer means the number of “beautiful number”.
Sample Input
2
1 11
999999993 999999999
Sample Output
10
2
Source
BestCoder Round #31
Recommend
hujie | We have carefully selected several similar problems for you: 5775 5774 5773 5772 5771
数位DP水题,没什么太大意思。。
#include <cstring>#include <cstdio>#include <string.h>#include <iostream>using namespace std;int num[15];int dp[15][15];//mark==1没前导0 mark==0有前导0int dfs(int pos,int pre,int over,int mark){ if(pos<0) return 1; if(dp[pos][pre]!=-1&&!over) return dp[pos][pre]; int last=over?num[pos]:9; int ans=0; for(int i=0;i<=last;i++) { if(mark==0||(pre>=i&&i!=0&&pre%i==0)) { ans+=dfs(pos-1,i,over&&i==last,mark||i); } } if(!over) dp[pos][pre]=ans; return ans;}int solve(int n){ int len=0; while(n) { num[len++]=n%10; n/=10; } return dfs(len-1,0,true,0);}int main(){ int t; scanf("%d",&t); memset(dp,-1,sizeof(dp)); while(t--) { int l,r; scanf("%d%d",&l,&r); printf("%d\n",solve(r)-solve(l-1)); }}
- HDU5179 beautiful number(数位DP)
- HDU5179 beautiful number 数位DP
- hdu5179---beautiful number
- hdu5179 beautiful number
- hdu5179 数位DP
- hdu5179 数位dp
- (hdu 5179)beautiful number(数位DP)
- hdu 5179 beautiful number(打表,数位DP)
- Codeforces 55D Beautiful Number (数位dp)
- CF 55D beautiful number(数位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)
- POJ 1465-Multiple(BFS-最小整倍数)
- hdu 1671
- 浅谈spring mvc和struts的比较
- 关于http
- iOS开发-腾讯sdk导致运行崩溃
- HDU5179 beautiful number(数位DP)
- 每日一linux命令(40)-------ifconfig命令
- delegate与event的区别
- LIS 最长递增子序列 hdu 5773
- 欢迎使用CSDN-markdown编辑器
- 上拉刷新下拉加载
- BZOJ1202: [HNOI2005]狡猾的商人 并查集
- Eric6的基础使用方法
- MYSQL 操作多个数据库