HDU - 3652

时间:2023-03-09 03:54:16
HDU - 3652
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<time.h>
#include<iostream>
#include<ctype.h>
#include<map>
#include<set>
#include<string>
#include<vector>
#include<algorithm>
#include<stdlib.h>
#include<queue>
#include<stack>
using namespace std;
#define LL long long
LL dp[][][],num[];
LL dfs(int pos,int mod,int st,int limit)//pos为数位从高位开始枚举(达到上限再枚举下一位),mod为对13求余,初始为0,st为状态,初始为0,limit为是否达到上限,1达到上限,0没有达到上限继续枚举
{
if(pos<)
return mod==&&st==;
if(!limit&&dp[pos][mod][st]!=-)
return dp[pos][mod][st];
int len=limit?num[pos]:;//判断上一位是否到上限,若达到则只能枚举到num【pos】,否则可以枚举0——9
int modx,stx;
LL ans=;
for(int i=;i<=len;i++)
{
modx=(mod*+i)%;
stx=st;
if(st==&&i!=)
stx=;
if(st==&&i==)
stx=;
if(st==&&i==)
stx=;
ans+=dfs(pos-,modx,stx,limit&&i==len);
}
if(!limit)//没有达到上限的都要存储一下该状态下的符合条件数;
dp[pos][mod][st]=ans;
return ans; }
LL sv(LL a)
{
int len=;
memset(dp,-,sizeof(dp));
memset(num,-,sizeof(num));
while(a)
{
num[len++]=a%;
a/=;
}
dfs(len-,,,);
}
int main()
{
LL n;
while(~scanf("%lld",&n))
{
LL ee=sv(n);
printf("%lld\n",ee);
}
}