# 数位DP-HDU-3652-B-number

153人阅读 评论(0)

B-number

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

Problem 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

Sample Output
1
1
2
2

Author
wqb0039

Source
2010 Asia Regional Chengdu Site —— Online Contest

1、这个数能被13整除；
2、这个数的数位有连续的13。

dfs过程：

//
//  main.cpp
//  数位DP-G-B-number
//
//  Created by 袁子涵 on 15/11/14.
//
//  0ms 1612KB

#include <iostream>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <algorithm>

using namespace std;

long long int dp[12][10][2][13];

long long int p(int n)
{
long long int out=1;
while (n) {
out*=10;
n--;
}
return out;
}

long long int dfs(int size,int head,int have,int mod)
{
}
long long int bit=p(size-1);
for (int i=0; i<10; i++) {
if (have) {
}
}
else
{
continue;
}
else
}
}
}

long long int solve(long long int n)
{
int num[12],l=0,flag=0,mod=0;
long long int sum=0;
memset(num, 0, sizeof(num));
while (n) {
num[++l]=n%10;
n/=10;
}
for (int i=l; i>0; i--) {
for (int j=0; j<num[i]; j++) {
if (flag || (j==3 && num[i+1]==1)) {
sum+=dfs(i, j, 1, (13-mod*p(i)%13)%13);
sum+=dfs(i, j, 0, (13-mod*p(i)%13)%13);
}
else
sum+=dfs(i, j, 1, (13-mod*p(i)%13)%13);
}
if (num[i+1]==1 && num[i]==3) {
flag=1;
}
mod=(mod*10+num[i])%13;
}
return sum;
}

int main(int argc, const char * argv[]) {
long long int n;
memset(dp, -1, sizeof(dp));
for (int i=0; i<10; i++) {
for (int j=0; j<=12; j++) {
dp[1][i][1][j]=0;
dp[1][i][0][j]=0;
}
dp[1][i][0][i]=1;
}
dp[2][1][1][0]=1;
while (scanf("%lld",&n)!=EOF) {
cout << solve(n+1) << endl;
}
return 0;
}

0
0

* 以上用户言论只代表其个人观点，不代表CSDN网站的观点或立场
个人资料
• 访问：33952次
• 积分：1802
• 等级：
• 排名：千里之外
• 原创：154篇
• 转载：0篇
• 译文：0篇
• 评论：4条
阅读排行
评论排行
最新评论