Building Blocks
Xiao Ming likes to build a number of bricks recently.
A total of 10 blocks, each building has a number, 0~9.
Rules for building blocks:
Each block is placed on top of the other two blocks, and must be smaller than the number of two blocks below.
At the end of the 4-storey pyramid, all the bricks must be used.
Here are the two qualifying methods:
0
1 2
3 4 5
6 7 8 9
0
3 1
7 5 2
9 8 6 4
Would you please calculate how many of these methods are there?
Please fill in the total number of purposes.
Note: You should submit an integer, do not fill in any superfluous content or descriptive text.
The topic type belongs to the whole arrangement selection;
Template See also: http://www.cnblogs.com/yang4869/p/8127269.html
Public classDemo1 {Static intCount=0; Public Static voidMain (string[] args) {intarr[]=New int[]{0,1,2,3,4,5,6,7,8,9}; DFS (arr,0,10); System.out.println (count); } Private Static voidDfsint[] arr,intNumintk) {//TODO auto-generated Method Stub if(num==k) { if(Panduan (arr)) {count++; } } for(inti=num;i<arr.length;i++) {swap (arr,num,i); DFS (Arr,num+1, K); Swap (arr,num,i); } } Private Static voidSwapint[] arr,intNuminti) {//TODO auto-generated Method Stub inttemp=Arr[num]; Arr[num]=Arr[i]; Arr[i]=temp; } Private Static BooleanPanduan (int[] arr) { //TODO auto-generated Method Stub /*0 1 2 3 4 5 6 7 8 9*/ if(arr[0]<arr[1]&&arr[0]<arr[2]){ if(arr[1]<arr[3]&&arr[1]<arr[4]){ if(arr[2]<arr[4]&&arr[2]<arr[5]){ if(arr[3]<arr[6]&&arr[3]<arr[7]){ if(arr[4]<arr[7]&&arr[4]<arr[8]){ if(arr[5]<arr[8]&&arr[5]<arr[9]){ return true; } } } } } } return false; }}
Answer: 768
Wrong or insufficient place to welcome correction!!
Finally share a favorite song (word):
the promise of self-abolition
word-song: Xu Song
Love has let me indulge in obsession
breaking up makes my heart I feel shadows
pain yourself say don't think too much
A friend is too lazy to say a word
you speak so freely.
bought my trust cheaply.
even the wind seems to laugh I'm so stupid
blew the hair, the air was lost.
the promise of your self-abolition
like a flower fire across the shore
No need to be responsible for what you don't need to hide
There's nothing wrong with it.
I can make you feel better if I leave
It's also a good choice.
If every word I say is wrong
It's better to be completely silent
only hope you have the result of happiness
Building Blocks (Java)-Blue Bridge Cup