Article 4 Enumeration

Source: Internet
Author: User

I. Thoughts

Sometimes we cannot find a rule when solving a problem. At this time, we are very confused, painful, and painful. Suddenly, we found that the number of candidate answers is within one million,

At this point, we thought of comparing them one by one from the candidate answers, until we find the correct solution.

 

Ii. Conditions

As mentioned above, enumeration is the final blow after we are helpless. We should try our best to abide by the following two conditions when using enumeration.

① No one on earth can tell me the potential laws of this problem.

② The set of candidate answers must be tolerable by a computer.

 

Iii. Example

The following is a number filling template. Each word indicates "0 ~" in the number ~ 9 ", then the number we enter must meet this template.

 

Idea 1): enumeration of "calculation", "method", and "brain" and "Question" respectively, with the complexity reaching O (N5 ).

// Value range of the word "count": For (INT I1 = 1; I1 <10; I1 ++) {// value range of the "method" word: For (INT I2 = 0; I2 <10; I2 ++) {// value range of "wash": For (INT I3 = 0; I3 <10; I3 ++) {// value range of the word "brain": For (INT I4 = 0; I4 <10; I4 ++) {// The value range of the word "Question" is for (INT I5 = 1; I5 <10; I5 ++) {count ++; // a conjecture value var guess = (I1*10000 + I2 * 1000 + I3 * 100 + I4 * 10 + I5) * I1; // final result value var result = I5 * 100000 + I5 * 10000 + I5 * 1000 + I5 * 100 + I5 * 10 + I5; If (guess = Result)

 

Idea 2): Calculate the product, calculate the multiplier, and calculate the multiplier. The complexity reaches O (n2 ).

// Quotient int [] resultarr = {111111,222 222, 333333,444 444, 555555,666 666, 777777,888 888, 999999}; // divisor int [] numarr = {1, 2, 3, 4, 5, 6, 7, 8, 9}; int COUNT = 0; For (INT I = 0; I <resultarr. count (); I ++) {for (Int J = 0; j <numarr. count (); j ++) {count ++; var result = resultarr [I]. tostring (); var num = numarr [J]. tostring (); var origin = (resultarr [I]/numarr [J]). tostring (); If (origin. lastordefault () = result. firstordefault () & origin. firstordefault () = num. firstordefault () & result. length-1 = origin. length)

 

Article 4 Enumeration

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.