标签:ch tot int long char Amount Degrees 40
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 #include<bits/stdc++.h> 2 using namespace std; 3 const int maxn=1e5+5; 4 int tot,e[40]; 5 long long c[40][40]; 6 int l,r,k,b; 7 template<class t>void red(t &x) 8 { 9 int w=1; 10 x=0; 11 char ch=getchar(); 12 while(ch>'9'||ch<'0') 13 { 14 if(ch=='-') 15 w=-1; 16 ch=getchar(); 17 } 18 while(ch>='0'&&ch<='9') 19 { 20 x=(x<<3)+(x<<1)+ch-'0'; 21 ch=getchar(); 22 } 23 x*=w; 24 } 25 void input() 26 { 27 freopen("input.txt","r",stdin); 28 } 29 void dv(int x) 30 { 31 tot=0; 32 while(x) 33 { 34 e[++tot]=x%b; 35 x/=b; 36 } 37 e[++tot]=0; 38 } 39 long long dfs(int pos,bool limit,int sum) 40 { 41 if(sum<0) 42 return 0; 43 if(pos==0) 44 return sum?0:1; 45 if(!limit&&~c[pos][sum]) 46 return c[pos][sum]; 47 int ans=0; 48 int up=limit?min(e[pos],1):1; 49 for(int i=0;i<=up;++i) 50 ans+=dfs(pos-1,limit&&(i==e[pos]),sum-i); 51 if(!limit) 52 c[pos][sum]=ans; 53 return ans; 54 } 55 long long solve(int x) 56 { 57 if(!x) 58 return 0; 59 dv(x); 60 memset(c,-1,sizeof(c)); 61 return dfs(tot,1,k); 62 } 63 void read() 64 { 65 red(l); 66 red(r); 67 red(k); 68 red(b); 69 } 70 void work() 71 { 72 printf("%lld",solve(r)-solve(l-1)); 73 } 74 int main() 75 { 76 input(); 77 read(); 78 work(); 79 return 0; 80 }View Code
定义c[i][j]表示到第i位时还需要j个数字凑齐
标签:ch,tot,int,long,char,Amount,Degrees,40 来源: https://www.cnblogs.com/Achensy/p/11003650.html
本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享; 2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关; 3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关; 4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除; 5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。