Building Blocks (Java)-Blue Bridge Cup

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.