Depth First search Code[vs] 11,164 color problems

Source: Internet
Author: User
Tags imap

/*dfs, you need to be aware of the format of the input test data. */
1#include <iostream>2#include <cstdlib>3#include <cstdio>4#include <cstddef>5#include <iterator>6#include <algorithm>7#include <string>8#include <locale>9#include <cmath>Ten#include <vector> One#include <cstring> A#include <map> -#include <utility> -#include <queue> the#include <stack> -#include <Set> - using namespacestd; - Const intINF =-0x3f3f3f3f; + Const intMAXN = -; - Const intModprime =3046721; +  A intN; at intcolorarr[Ten]; - Charimap[Ten][Ten]; - intAnswer =0; -  - BOOLIsadjoincolor (intNodeintcolor) - { in      for(inti =0; I < n; ++i) -     { to         if((imap[node][i] = ='1') && (color = =Colorarr[i])) +         { -             return true; the         } *     } $     return false;Panax Notoginseng } -  the voidSolve (intnodenum) + { A     if(Nodenum = =N) the     { +++answer; -         return; $     } $      for(intcolor =1; Color <=4; ++color) -     { -         if(!isadjoincolor (nodenum, color)) the         { -Colorarr[nodenum] =color;WuyiSolve (Nodenum +1); theColorarr[nodenum] =-1; -         } Wu     } - } About  $  - intMain () - { - #ifdef HOME AFreopen ("inch","R", stdin); +     //freopen ("Out", "w", stdout); the #endif -  $Fill (Colorarr, Colorarr +Ten, -1); theCIN >>N; the      for(inti =0; I < n; ++i) the     { the          for(intj =0; J < N; ++j) -         { inCIN >>Imap[i][j]; the         } the     } AboutSolve (0); thecout << Answer <<Endl; the  the  + #ifdef HOME -Cerr <<"Time Elapsed:"<< clock ()/Clocks_per_sec <<"Ms"<<Endl; the _CrtDumpMemoryLeaks ();Bayi #endif the     return 0; the}

Depth First search Code[vs] 11,164 color problems

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.