Blue Bridge Cup-several routines commonly used in recursion

Source: Internet
Author: User

To find the size of the largest common sub-sequence
 Public classMaximum Common sub-sequence { Public Static voidMain (string[] args) {intK=F ("abc", "ADFEFEXCGFD");    System.out.println (k); }    Private Static intf (String s1, string s2) {if(S1.length () ==0| | S2.length () ==0)return0; if(S1.charat (0) ==s2.charat (0))            returnF (s1.substring (1), s2.substring (1)) +1; Else            returnMath.max (f (s1.substring (1), S2), F (s1,s2.substring (1))); }}
The full array of alphabetic arrays or numbers
/*a b c a C b b a C b c a C B a c a B*/ Public classfull Array { Public Static voidMain (string[] args) {Char[] data= "123456789". ToCharArray (); F (Data,0); }    Private Static voidFChar[] Data,intk) {if(k==data.length) { for(inti = 0; i < data.length; i++) {System.out.print (Data[i]+" ");        } System.out.println (); }                 for(intj = k; J < Data.length; J + +) {            { CharT=DATA[K];d ata[k]=data[j];d ata[j]=t; }//Temptationf (data,k+1);//Recursive{CharT=DATA[K];d ata[k]=data[j];d ata[j]=t; }//Backtracking        }    }}
Super large numbers and rounding of decimals (E,zheigehediguimeiguanxi)
ImportJava.math.BigDecimal;ImportJava.math.BigInteger; Public classlarge numbers and fractions { Public Static voidMain (string[] args) {//a large numberBigInteger bi=biginteger.valueof (1); BigInteger sum=biginteger.valueof (0);  for(inti = 0; I < 64; i++) {sum=sum.add (BI); Bi=bi.multiply (Biginteger.valueof (2));                } System.out.println (sum); //Rounding of decimals        Doubled=1234.546556; BigDecimal BD=NewBigDecimal (d); DoubleD1=bd.setscale (2, bigdecimal.round_half_up). Doublevalue ();    System.out.println (D1); }}

Blue Bridge Cup-several routines commonly used in recursion

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.