标签:microsoft bre ble 路径 body 暴搜 include string font
搭积木
一种积木搭建方式,高为H的积木,最底层有M个积木,每一层的积木数是他的低一层的积木数+1或-1。总共有N个积木。(且每行积木数不超过10)
比如上图N=13 H=6 M=2。
13 6 2
1
3
-1
3
2 1 2 3 2 3
2 3 2 3 2 1
1 #include<cstdio> 2 #include<iostream> 3 #include<cstring> 4 using namespace std; 5 int n,h,m; 6 long long f[61][11][541],qst; 7 inline void work(long long x,int h,int now,int a) 8 { 9 printf("%d ",now); 10 if(h==1) return; 11 a-=now; 12 if(x>f[h-1][now-1][a]) 13 { 14 x-=f[h-1][now-1][a]; 15 now++; 16 } 17 else now--; 18 work(x,h-1,now,a); 19 return; 20 } 21 int main() 22 { 23 scanf("%d%d%d",&n,&h,&m); 24 for(int i=1;i<=min(h+m-1,10);i++) f[1][i][i]=1; 25 for(int i=2;i<=h;i++) 26 for(int j=1;j<=min(h+m-1,10);j++) 27 for(int k=1;k<=n;k++) f[i][j][k]=f[i-1][j-1][k-j]+f[i-1][j+1][k-j]; 28 printf("%lld",f[h][m][n]); 29 while(1) 30 { 31 scanf("%lld",&qst); 32 if(qst==-1) break; 33 printf("\n"); 34 work(qst,h,m,n); 35 } 36 return 0; 37 }
标签:microsoft bre ble 路径 body 暴搜 include string font
原文地址:http://www.cnblogs.com/the-unbeatable/p/6413013.html