# 数位DP入门详解+题目推荐

$update:2019-9-6$

#include<iostream>
#include<cstring>
#include<cstdio>
#include<cctype>
#include<cmath>
#define ll long long
#define gc() getchar()
#define maxn 15
using namespace std;

ll a=0;int f=0;char p=gc();
while(!isdigit(p)){f|=p=='-';p=gc();}
while(isdigit(p)){a=(a<<3)+(a<<1)+(p^48);p=gc();}
return f?-a:a;
}
void write(ll a){
if(a>9)write(a/10);
putchar(a%10+'0');
}

int x,y,d[maxn],l;
ll f[maxn][maxn];
if(!pos)return 1;  //如果所有位都已经构造完了，说明这是一个合法数值，贡献加一
int up=limit?d[pos]:9;ll ans=0;  //up就是当前位选数的右端点
for(int i=0;i<=up;++i){  //枚举构造
}
return ans;
}

ll solve(int k){
l=0;
while(k){  //这里是为了记录一下当前范围最大是几位
d[++l]=k%10;
k/=10;
}
return dfs(l,0,1,1);
}

int main(){memset(f,-1,sizeof f);
write(solve(y)-solve(x-1));  //答案要求是[x,y]之间的windy数，所以减去[0,x)的windy数即可
return 0;
}


#include<iostream>
#include<cstring>
#include<cstdio>
#include<cctype>
#define ll long long
#define gc() getchar()
#define maxn 15
using namespace std;

ll a=0;int f=0;char p=gc();
while(!isdigit(p)){f|=p=='-';p=gc();}
while(isdigit(p)){a=(a<<3)+(a<<1)+(p^48);p=gc();}
return f?-a:a;
}
void write(ll a){
if(a>9)write(a/10);
putchar(a%10+'0');
}

int l,d[maxn];
ll x,y,f[maxn][maxn];
ll dfs(int pos,int s,int x,bool limit,bool lead){
if(!pos)return s;
int up=limit?d[pos]:9;ll ans=0;
for(int i=0;i<=up;++i)
return ans;
}

ll solve(ll k,int a){
l=0;
while(k){
d[++l]=k%10;
k/=10;
}
return dfs(l,0,a,1,1);
}

int main(){
for(int i=0;i<=9;++i){
memset(f,-1,sizeof f);
printf("%lld ",solve(y,i)-solve(x-1,i));
}
return 0;
}


#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cctype>
#define ll long long
#define gc getchar
#define maxn 15
using namespace std;

ll a=0;int f=0;char p=gc();
while(!isdigit(p)){f|=p=='-';p=gc();}
while(isdigit(p)){a=(a<<3)+(a<<1)+(p^48);p=gc();}
return f?-a:a;
}ll l,r;int d[maxn];

ll f[maxn][maxn][maxn][5][5][5][5];
ll dfs(int pos,int pre,int pre2,int limit,int c,int ba,int si){
if(ba&si)return 0;
if(!pos)return c;
if(~f[pos][pre][pre2][limit][c][ba][si])
return f[pos][pre][pre2][limit][c][ba][si];
int up=limit?d[pos]:9,down=pos==11;ll sum=0;
for(int i=down;i<=up;++i)
sum+=dfs(pos-1,i,pre,limit&(i==up),c|(i==pre&&i==pre2),ba|(i==8),si|(i==4));
return f[pos][pre][pre2][limit][c][ba][si]=sum;
}
inline ll solve(ll x){memset(f,-1,sizeof f);
memset(d,0,sizeof d);
if(x<1e10)return 0;
int len=0;
while(x){
d[++len]=x%10;
x/=10;
}
return dfs(len,11,11,1,0,0,0);
}

int main(){
printf("%lld\n",solve(r)-solve(l-1));
return 0;
}


### 题目推荐

[HAOI2010]计数

[AHOI2009]同类分布

posted @ 2019-09-03 17:54  子谦。  阅读(...)  评论(...编辑  收藏
Live2D
//雪