Classic Algorithm Review 1

Source: Internet
Author: User

This article according to the main line of the garden Master of the process to learn, in the future will also add some, I hope to improve
Public classMain { Public Static voidMain (string[] args) {//TODO auto-generated Method Stub /** Rooster Five Money One, hen three money A, chicken three only a penny * with 100 text money to buy 100 chickens, which cocks, hens, chickens must have, ask each how many only*/ for(inti = 1; I < 20;i++){ for(intj = 1; J < 33; J + +){ intK = 100-i-J; if((0 = = k% 3) && (I*5+J*3+K/3) {System.out.println (i+ "" +j+ "" +k); } } } }}

 Public classMain2 { Public Static voidMain (string[] args) {//TODO auto-generated Method Stub        /** Five co-Wells * Five family common well, a family of rope with two not enough, to use a rope of b family * b home with three rope not enough, to use the third home of A * C home with four rope not enough, but also to use a Dinggu * Ding home with five not enough, but also to use an E home of a * E household six is not enough, but also to use a home of a * Last ask how deep the well, each family of rope how long*/         for(inti = 1; I < 5; i++){            inth = 721 *i; intA = 265 *i; intb = 191 *i; intc = 148 *i; intD = 129 *i; intE = 76 *i; System.out.println (A+ "" + B + "" +c+ "" +d+ "" +e+ "" +h); }    }}
Five common well problems: think more about the problem, do not immediately, think more, perhaps there will be a better way.
 Public classMain3 {Static intSum (intIintj) {        if(10 = =i) {            returnJ; }        returnSum (i+1,2* (j+1)); }     Public Static voidMain (string[] args) {//TODO auto-generated Method Stub        /** The monkey picked a few peaches on the first day, ate half of them immediately, and ate one more when they were not satisfied. The next morning, the rest of the peach eaten half, or not enjoyable and eat one more. After every day eat the rest of the last half and add one. By the 10th day there was just one left.        Q. How many peaches did the monkeys pick on the first day? Tail recursion*/        intsum = SUM ();    SYSTEM.OUT.PRINTLN (sum); }}
 Public classMain4 {StaticString str1 = "ACGBFH"; StaticString str2 = "Ahka";  Public Static voidMain (string[] args) {//TODO auto-generated Method Stub        /** Longest common sub-sequence*/        intA =LCS (STR1,STR2);            System.out.print (a); }    Static intLCS (String str1,string str2) {intA[][] =New int[Str1.length () +1] [Str2.length () +1];  for(inti = 0; I <=str1.length (); i++) {a[i][0] = 0; }         for(intj = 0; J <=str2.length (); J + +) {a[0][J] = 0; }         for(inti = 1; I <= str1.length (); i++){             for(intj = 1; J <= Str2.length (); J + +){                if(Str1.getbytes () [i-1] = = Str2.getbytes () [j-1]) {A[i][j]= A[i-1][j-1] +1; }                Else{A[i][j]= Math.max (A[i-1][j], a[i][j-1]); }            }        }        returna[str1.length ()][str2.length ()]; }}

The longest common sub-sequence is a classical algorithm.

Classic Algorithm Review 1

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.