Java Total combination algorithm

Source: Internet
Author: User

     Public Static voidCombination (int[] s) {if(S.length = = 0) {            return; }        intLen =s.length; intn = 1 <<Len; //from 1 cycles to 2^len-1         for(inti = 1; I < n; i++) {StringBuffer sb=NewStringBuffer (); //look at any one of the values in the first layer loop that is 1[such as ab,011], and if it is 1, the corresponding character exists, printing the current combination.             intsum = 0;  for(intj = 0; J < Len; J + +) {                if((I & (1 << j))! = 0) {//The corresponding bit is 1, then the corresponding character is output                    intA =S[j]; Sum= Sum +A;                Sb.append (S[j]); }} System.out.println ("Combination:" + SB + ", Sum:" +sum); }    }

1190000002710424

Java Total combination algorithm

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.