hdu 4722 数位dp 简单题

Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u

[]  [Go Back]  [Status]  

Description

A wqb-number, or B-number for short, is a non-negative integer whose decimal form contains the sub- string "13" and can be divided by 13. For example, 130 and 2613 are wqb-numbers, but 143 and 2639 are not. Your task is to calculate how many wqb-numbers from 1 to n for a given integer n.
 

Input

Process till EOF. In each line, there is one positive integer n(1 <= n <= 1000000000).
 

Output

Print each answer in a single line.
 

Sample Input

  
  
13 100 200 1000


求a到b区间各位和能整除10的个数,简单数位dp取mod==0的部分。

代码:

/* ***********************************************
Author :xianxingwuguan
Created Time :2014-2-7 13:48:09
File Name :1.cpp
************************************************ */
#pragma comment(linker, "/STACK:102400000,102400000")
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <stdlib.h>
#include <string.h>
#include <limits.h>
#include <string>
#include <time.h>
#include <math.h>
#include <queue>
#include <stack>
#include <set>
#include <map>
using namespace std;
#define INF 0x3f3f3f3f
#define eps 1e-8
#define pi acos(-1.0)
typedef __int64 ll;
ll dp[22][12],num[22];
ll dfs(ll pos,ll mod,bool flag){
	if(pos==0)return mod==0;
	if(flag&&dp[pos][mod]!=-1)return dp[pos][mod];
	ll u=flag?9:num[pos];
	ll ans=0;
	for(ll d=0;d<=u;d++)
		ans+=dfs(pos-1,(mod+d)%10,flag||d<u);
	if(flag)dp[pos][mod]=ans;
	return ans;
}
ll solve(ll x){
	ll len=0;
	while(x){
		num[++len]=x%10;
		x/=10;
	}
	return dfs(len,0,0);
}
int main()
{
       ll i,j,k,m,a,b,T,t;
       memset(dp,-1,sizeof(dp));
       scanf("%I64d",&T);
       for(t=1;t<=T;t++)
       {
              scanf("%I64d%I64d",&a,&b);
              printf("Case #%I64d: ",t);
              if(a==0)printf("%I64d\n",solve(b));
              else printf("%I64d\n",solve(b)-solve(a-1));
       }
       return 0;
}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值