题目描述
小明最近喜欢搭数字积木,一共有10块积木,每个积木上有一个数字,0~9。
搭积木规则:每个积木放到其它两个积木的上面,并且一定比下面的两个积木数字小。
最后搭成4层的金字塔形,必须用完所有的积木
下面是两种合格的搭法:
0
1 2
3 4 5
6 7 8 9
0
3 1
7 5 2
9 8 6 4
请你计算这样的搭法一共有多少种?
输出格式
一个整数表示答案
暴就完了
#include <string.h>
#include <stdio.h>
int main(){
int a=0,s,d,f,g,h,j,k,l,z;
int i=0;
for(s=1;s<10;s++){
for(d=1;d<10;d++){
for(f=1;f<10;f++){
for(g=1;g<10;g++){
for(h=1;h<10;h++){
for(j=1;j<10;j++){
for(k=1;k<10;k++){
for(l=1;l<10;l++){ //0~9的和为45
z=45-s-d-f-g-h-j-k-l; //减少一个循环,减少时间复杂度
if(f>s&&g>s&&s!=d&&s!=f&&s!=g&&s!=h&&s!=j&&s!=k&&s!=l){
if(g>d&&h>d&&d!=f&&d!=g&&d!=h&&d!=j&&d!=k&&d!=l){
if(j>f&&k>f&&f!=g&&f!=h&&f!=j&&f!=k&&f!=l){
if(k>g&&l>g&&g!=h&&g!=j&&g!=k&&g!=l){
if(l>h&&z>h&&h!=j&&h!=k&&h!=l){
if(j!=k&&j!=l){
if(k!=l){
i++;
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
printf("%d",i);
return 0;
}