标签:Fix iostream memset 数字 bool out include 个数 abs
1 #include<iostream> 2 #include<cstring> 3 #include<cmath> 4 using namespace std; 5 int e[10001],cnt; 6 long long f[12][12][2][2]; 7 long long dp(int pos,int pre,bool zero,bool lim) 8 { 9 if (pos<1) return 1; 10 if (f[pos][pre][zero][lim]!=-1) return f[pos][pre][zero][lim]; 11 int end=lim?e[pos]:9; 12 int ans=0; 13 for (int i=0;i<=end;i++) 14 { 15 if (abs(i-pre)>=2||zero) 16 { 17 ans+=dp(pos-1,i,zero&&(i==0),lim&&(i==end)); 18 } 19 } 20 return f[pos][pre][zero][lim]=ans; 21 } 22 long long calc(int x) 23 { 24 memset(f,-1,sizeof(f)); 25 memset(e,0,sizeof(e)); 26 cnt=0; 27 while (x) e[++cnt]=x%10,x/=10; 28 return dp(cnt,0,1,1); 29 } 30 int main () 31 { 32 int a,b; 33 cin>>a>>b; 34 cout<<calc(b)-calc(a-1); 35 }
标签:Fix iostream memset 数字 bool out include 个数 abs
原文地址:https://www.cnblogs.com/zjzjzj/p/11330411.html