标签:turn 组合数学 \n for sum cst using ring clu
参照博客 https://blog.csdn.net/lyy289065406/article/details/6648458
1 #include <iostream> 2 #include <cstdio> 3 #include <cmath> 4 #include <cstring> 5 #include <algorithm> 6 #include <queue> 7 #include <stack> 8 #include <vector> 9 using namespace std; 10 int c[35][35]={0}; 11 int bin[35]={0}; 12 int roun(int n) 13 { 14 int sum=0; 15 int k=n; 16 bin[0]=0; 17 while(k) 18 { 19 bin[++bin[0]]=k%2; 20 k>>=1; 21 } 22 for(int i=1;i<bin[0]-1;i++) 23 for(int j=i/2+1;j<=i;j++) 24 sum+=c[i][j]; 25 int zero=0; 26 for(int i=bin[0]-1;i>0;i--) 27 { 28 if(bin[i]==1) 29 { 30 for(int j=(bin[0]+1)/2-(zero+1);j<=i-1;j++) 31 sum+=c[i-1][j]; 32 } 33 else 34 zero++; 35 } 36 return sum; 37 } 38 int main(int argc, char *argv[]) 39 { 40 int a,b,sum=0; 41 for(int i=0;i<=33;i++) 42 { 43 for(int j=0;j<=i;j++) 44 { 45 if(!j||i==j) 46 c[i][j]=1; 47 else 48 c[i][j]=c[i-1][j-1]+c[i-1][j]; 49 } 50 } 51 scanf("%d%d",&a,&b); 52 printf("%d\n",roun(b+1)-roun(a)); 53 return 0; 54 }
标签:turn 组合数学 \n for sum cst using ring clu
原文地址:https://www.cnblogs.com/huluxin/p/9749991.html