社区讨论
记搜30pts玄关求条
P2657[SCOI2009] windy 数参与者 1已保存回复 1
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 1 条
- 当前快照
- 1 份
- 快照标识符
- @mhizrry7
- 此快照首次捕获于
- 2025/11/03 18:23 4 个月前
- 此快照最后确认于
- 2025/11/03 18:23 4 个月前
rt,
CPP#include<bits/stdc++.h>
#define ll long long
//#define int ll
using namespace std;
const int N=1e6+5;
int a, b, dp[10][11][2], n;
int f(int len, int pre, int free, int sf){
if(!len)
return 1;
if(dp[len][pre][free]!=-1)
return dp[len][pre][free];
int ans=0, cur=(n/sf)%10;
if(free){
if(pre==10){
ans+=f(len-1, 10, 1, sf/10);
for(int i=1; i<10; i++)
ans+=f(len-1, i, 1, sf/10);
}else{
for(int i=0; i<10; i++)
if(pre-2>=i || pre+2<=i)
ans+=f(len-1, i, 1, sf/10);
}
}else{
if(pre==10){
ans+=f(len-1, 10, 1, sf/10);
for(int i=1; i<cur; i++)
ans+=f(len-1, i, 1, sf/10);
ans+=f(len-1, cur, 0, sf/10);
}else{
for(int i=0; i<10; i++){
if(i<=pre-2 || i>=pre+2)
if(i<cur)
ans+=f(len-1, i, 1, sf/10);
else if(i==cur)
ans+=f(len-1, i, 0, sf/10);
}
}
}
dp[len][pre][free]=ans;
return ans;
}
int len, offset, t;
int cnt(int x){
if(!x)
return 1;
offset=1; len=1; n=x; t=x/10;
while(t){
offset*=10;
len++;
t/=10;
}
for(int i=0; i<=len; i++)
for(int j=0; j<=10; j++)
dp[i][j][0]=dp[i][j][1]=-1;
return f(len, 10, 0, offset);
}
int main(){
cin>>a>>b;
cout<<cnt(b)-cnt(a-1)<<endl;
return 0;
}
回复
共 1 条回复,欢迎继续交流。
正在加载回复...