标签:style blog color os io ar for div 问题
题意:给定x,y,K,B,要求找出在区间[x,y]内的正整数个数,使它们满足恰好由K个不同的某个B的幂组成
例如
1 #include <iostream> 2 #include <cstring> 3 using namespace std; 4 int x,y,k,b; 5 int len,Bbas[51]; 6 int f[51][21][2]; //1 等于 0 小于 7 int solve(int p){ 8 len=0;memset(Bbas,0,sizeof(Bbas)); 9 memset(f,0,sizeof(f)); 10 int t=p; 11 while (t){ 12 Bbas[++len]=t%b;t=t/b; 13 } 14 if (Bbas[len]==1) {f[len][1][1]=1;f[len][0][0]=1;} 15 else {f[len][1][0]=1;f[len][0][0]=1;} 16 for (int i=len-1;i>=1;i--) 17 for (int j=0;j<=k;j++){ 18 if (j==0) { 19 f[i][j][0]=1; 20 }else { 21 if (Bbas[i]>1) { 22 f[i][j][0]=f[i+1][j-1][1]+f[i+1][j-1][0]+f[i+1][j][1]+f[i+1][j][0]; 23 }else { 24 if (Bbas[i]==1) { 25 f[i][j][0]=f[i+1][j][1]+f[i+1][j][0]+f[i+1][j-1][0]; 26 f[i][j][1]=f[i+1][j-1][1]; 27 } 28 if (Bbas[i]==0) { 29 f[i][j][0]=f[i+1][j][0]+f[i+1][j-1][0]; 30 f[i][j][1]=f[i+1][j][1]; 31 } 32 } 33 } 34 } 35 return f[1][k][0]+f[1][k][1]; 36 } 37 int main(){ 38 cin>>x>>y>>k>>b; 39 cout<<solve(y)-solve(x-1)<<endl; 40 return 0; 41 }
标签:style blog color os io ar for div 问题
原文地址:http://www.cnblogs.com/yzh119/p/3947954.html