0
点赞
收藏
分享

微信扫一扫

搭积木


小明最近喜欢搭数字积木, 
一共有10块积木,每个积木上有一个数字,0~9。 
搭积木规则: 
每个积木放到其它两个积木的上面,并且一定比下面的两个积木数字小。 
最后搭成4层的金字塔形,必须用完所有的积木。


下面是两种合格的搭法: 

1 2 
3 4 5 
6 7 8 9



3 1 
7 5 2 
9 8 6 4 

请你计算这样的搭法一共有多少种?


#include<iostream>
#include<algorithm>
using namespace std;

int main()
{
	int cnt=0;
	string s="0123456789";
	do {
		if(s[0]<s[1] &&s[0]<s[2] && s[1]<s[3] && s[1]<s[4] && s[2]<s[4] &&s[2]<s[5] 
		&& s[3]<s[6] &&s[3]<s[7] && s[4]<s[7]&& s[4]<s[8] &&s[5]<s[8] &&s[5]<s[9]) {
			cnt++;
		}
	}while(next_permutation(s.begin(),s.end()));
	
	cout<<cnt;
	return 0;
}





举报

相关推荐

0 条评论