题意:给出n,问1-n中有13且能整除13的数数量。
就是hd3555和codeforces beautiful number的合成版。dp记录待填长度,是否带有13,前面数的模13余数,前一个数是k的时候的b-number数数量。
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cstring>
#include <map>
#include <queue>
#include <set>
#include <cassert>
using namespace std;
const double EPS=1e-;
const int SZ=,INF=0x7FFFFFFF;
typedef long long lon;
int dp[][][][]; int dfs(int pos,int sum,int pre,int limit,string &str,int inc)
{
if(pos==str.size())return inc&&(sum%==);
if(!limit&&dp[str.size()-pos-][sum][pre][inc]!=-)return dp[str.size()-pos-][sum][pre][inc];
int up=limit?str[pos]-'':;
int res=;
for(int i=;i<=up;++i)
{
int nexsum=(sum*+i)%;
if(pre==&&i==)res+=dfs(pos+,nexsum,i,limit&&i==str[pos]-'',str,);
else res+=dfs(pos+,nexsum,i,limit&&i==str[pos]-'',str,inc);
//if(pos==1&&pre==1)cout<<i<<" "<<res<<" "<<endl;
}
if(!limit)dp[str.size()-pos-][sum][pre][inc]=res;
return res;
} int work(string &str)
{
return dfs(,,,,str,);
} int main()
{
std::ios::sync_with_stdio();
//freopen("d:\\1.txt","r",stdin);
//lon casenum;
//cin>>casenum;
memset(dp,-,sizeof(dp));
//for(lon time=1;time<=casenum;++time)
string str;
for(lon time=;cin>>str;++time)
{
cout<<work(str)<<endl;
}
return ;
}