AcWing 311. 月之谜 数位dp
#include<iostream> #include<cstring> #include<cstdio> #include<algorithm> using namespace std; #define int long long typedef long long ll; const int N=200; int read() { int res=0,ch,flag=0; if((ch=getchar())=='-') //判断正负 flag=1; else if(ch>='0'&&ch<='9') //得到完整的数 res=ch-'0'; while((ch=getchar())>='0'&&ch<='9') res=res*10+ch-'0'; return flag?-res:res; } int mod; int l,r,a[N],dp[N][N][N]; int dfs(int pos,int sum,int now,int limit) { if(!pos) return (sum==mod)&&(now==0); if(!limit&&dp[pos][sum][now]!=-1) return dp[pos][sum][now]; int up=limit?a[pos]:9; int res=0; for(int i=0;i<=up;i++) res+=dfs