mirror of
https://github.com/Kiritow/OJ-Problems-Source.git
synced 2024-03-22 13:11:29 +08:00
Create 3652_kg20006.cpp
From http://acm.hdu.edu.cn/discuss/problem/post/reply.php?postid=27200&messageid=1&deep=0
This commit is contained in:
parent
e1155b9d5e
commit
2611e494ec
35
HDOJ/3652_kg20006.cpp
Normal file
35
HDOJ/3652_kg20006.cpp
Normal file
|
@ -0,0 +1,35 @@
|
|||
#include<bits/stdc++.h>
|
||||
#define ll long long int
|
||||
using namespace std;
|
||||
ll num[30];
|
||||
ll dp[30][15][5];
|
||||
ll dfs(int pos, int mod, int st, bool f){
|
||||
if(pos < 1) return st == 2 && mod == 0;
|
||||
if(!f && dp[pos][mod][st] != -1) return dp[pos][mod][st];
|
||||
int end = f? num[pos] : 9;
|
||||
ll res = 0;
|
||||
for(int i = 0; i <= end; ++i){
|
||||
int nmod = (mod*10 + i) %13;
|
||||
bool nf = (f && i == end);
|
||||
if(st == 2 || (st == 1 && i == 3)) res += dfs(pos-1, nmod, 2, nf);
|
||||
else if(i == 1) res += dfs(pos-1, nmod, 1, nf);
|
||||
else res += dfs(pos-1, nmod, 0, nf);
|
||||
}
|
||||
if(!f) dp[pos][mod][st] = res;
|
||||
return res;
|
||||
}
|
||||
ll solve(ll n){
|
||||
int len = 0;
|
||||
while(n){
|
||||
num[++len] = n%10;
|
||||
n /= 10;
|
||||
}
|
||||
return dfs(len, 0, 0, 1);
|
||||
}
|
||||
int main(){
|
||||
ll n;
|
||||
while(scanf("%lld", &n) != EOF){
|
||||
memset(dp, -1, sizeof(dp));
|
||||
printf("%lld\n", solve(n));
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user