HDOJ 5179 beautiful number

beautiful number

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 707    Accepted Submission(s): 451


Problem Description
Let A=ni=1ai10ni(1ai9)( n is the number of A's digits). We call A as “beautiful number” if and only if a[i]a[i+1] when 1i<n and a[i] mod a[j]=0 when 1in,i<jn(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(1LR109).
 
Output
For each case, output an integer means the number of “beautiful number”.
 

Sample Input

2 1 11 999999993 999999999
 

Sample Output

10 2

#include 
using namespace std;
#define mst(a,b) memset((a),(b),sizeof(a))
#define f(i,a,b) for(int i=(a);i<(b);i++)
#define maxn 100005
#define mod 10001
#define ll long long
#define rush() int t;scanf("%d",&t);while(t--)
int dp[11][11],a[11];
void init()
{
    mst(dp,0);
    f(i,1,10)
        dp[1][i]=1;
    f(i,2,11)
    f(j,0,10)
    {
        f(k,1,10)
        {
            if(j%k==0)
                dp[i][j]+=dp[i-1][k];
        }
        if(!j) dp[i][j]+=dp[i-1][0];
    }
}
int fun(int x)
{
    int len=1;
    while(x)
    {
        a[len++]=x%10;
        x/=10;
    }
    a[len--]=0;
    int ans=0;
    for(int i=len; i>=1; i--)
    {
        if(i==len)
        {
            f(j,0,a[i])
            ans+=dp[i][j];
        }
        else
        {
            if(a[i]==0)
                break;
            for(int j=1; j<=a[i+1]&&j

你可能感兴趣的:(数位DP&记忆化搜索)