Usaco 1.4 the clocks

Source: Internet
Author: User

(1) Each conversion column can appear three times at most, because if it appears four times, it is equivalent to turning a circle, equal to 0. There are a total of 4 ^ 9 cases, which can be traversed.

For example:

  1. Void DFS (INT clocks [])
  2. {
  3. For (INT I1 = 0; I1 <4; I1 ++)
  4. For (INT I2 = 0; I2 <4; I2 ++)
  5. For (INT I3 = 0; I3 <4; I3 ++)
  6. For (INT I4 = 0; I4 <4; I4 ++)
  7. For (INT I5 = 0; I5 <4; I5 ++)
  8. For (INT I6 = 0; I6 <4; I6 ++)
  9. For (INT i7 = 0; i7 <4; i7 ++)
  10. For (INT i8 = 0; i8 <4; i8 ++)
  11. For (INT I9 = 0; I9 <4; I9 ++)
  12. {Int means [9] = {I1, I2, I3, I4, I5, I6, i7, i8, I9}; If (is (clocks, means ))
  13. {Int last; For (INT I = 8; I>-1; I --) if (means [I]! = 0) {last = I; break;} For (INT I = 0; I <last;
  14. I ++) while (means [I]! = 0) {fout <I + 1 <''; -- means [I];}
  15. While (means [last]> 1) {fout <last + 1 <''; -- means [last];} fout <last + 1 <Endl ;}
  16. }
  17. }

 

(2) I originally wanted to use BFs, and the result code only passed the first two test data, 3rd of which seriously timed out on my computer ~ It has been running for N years ~ The efficiency is too low. Because the number of nodes to be convenient increases by 9 ^ N, the third test data (the answer is 11 digits) will stop.

 

(3) I finally used the Internet to facilitate space solution based on different situations.

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.