#pragma GCC optimize(2)
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int Case = 1;
ll n, dp[25][15][3];
int pos[15];
ll dfs(int p, int mod, int status, bool up) {
if(!p) return status==2&&mod==0;
if(!up && dp[p][mod][status]) return dp[p][mod][status];
ll res = 0;
int u = up?pos[p]:9;
for(int i = 0; i <= u; i++) {
int ns = status;
if(status == 0 && i == 1)
ns = 1;
else if(status == 1 && i != 3 && i != 1)
ns = 0;
else if(status == 1 && i == 3)
ns = 2;
res += dfs(p-1, (mod*10+i)%13, ns, up&&i==u);
}
if(!up) dp[p][mod][status] = res;
return res;
}
void solve() {
int cnt = 0;
while(n) {
pos[++cnt] = n%10;
n /= 10;
}
printf("%lld\n", dfs(cnt, 0, 0, 1));
return;
}
int main() {
while(scanf("%lld", &n) == 1) {
solve();
}
return 0;
}
hdu3652【数位dp】【取模】
最新推荐文章于 2020-10-06 15:51:50 发布