#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#define LL long long
using namespace std;
int dp[15][15][2][10];
int bit[15];
int dfs(int pos,int num,int t,int e,bool flag)
{
if(pos == 0) return t && (num == 0);
if(!flag && dp[pos][num][t][e] != -1)
return dp[pos][num][t][e];
int end = flag ? bit[pos] : 9;
int ans = 0;
for(int i=0;i<=end;i++)
{
ans += dfs(pos-1,(num * 10 + i) % 13, t||(e==1&&i==3), i,flag &&(i==end));
}
if(!flag) dp[pos][num][t][e] = ans;
return ans;
}
int solve(int n)
{
memset(bit, 0, sizeof(bit));
int len = 0;
while(n)
{
bit[++len] = n % 10;
n /= 10;
}
return dfs(len,0,0,0,1);
}
int main()
{
int n;
while(scanf("%d", &n)!=EOF)
{
memset(dp, -1, sizeof(dp));
printf("%d\n", solve(n));
}
return 0;
}
HDU 3652 B-number(数位DP)
最新推荐文章于 2021-08-09 22:15:39 发布