DFS ZOJ 1002/hdoj 1045 Fire Net

Source: Internet
Author: User

Topic Portal

1 /*2 Test instructions: Put a battery in a matrix, meet the ranks of up to only one fort, unless there is a wall (X) apart, ask the maximum number of batteries to put3 Search (DFS): Data small, 4 * 4 can be used DFS, starting from (0,0), go to (n-1,n-1) left lower corner, x = cnt/n; y = cnt% n; Update coordinates,4 until all the points are gone, as you go from the left to the right, just determine whether the upper left side of the current point satisfies the condition.5 Note: The current point can not be the case of the blasting table should also consider6 G[x][y] = = ' O '; Errors for half a day before checking out:)7 */8#include <cstdio>9#include <iostream>Ten#include <cstring> One#include <string> A#include <algorithm> -#include <map> -#include <cmath> the using namespacestd; -  - Const intMAXN = 1e4 +Ten; - Const intINF =0x3f3f3f3f; + Charg[5][5]; - intans; + intN; A  at BOOLOkintXinty) - { -      for(inti=y-1; i>=0; --i) -     { -         if(G[x][i] = ='o')return false; -         Else if(G[x][i] = ='X') Break; in     } -      for(inti=x-1; i>=0; --i) to     { +         if(G[i][y] = ='o')return false; -         Else if(G[i][y] = ='X') Break; the     } *  $     return true;Panax Notoginseng } -  the voidDFS (intCntinttot) + { A     if(CNT = = n *N) the     { +         if(Ans < tot) ans =tot; -         return ; $     } $  -     Else -     { the         intx = CNT/N; -         inty = cnt%N;Wuyi  the         if(G[x][y] = ='.'&& ok (x, y) = =true) -         { WuG[x][y] ='o'; -DFS (cnt+1, tot+1); AboutG[x][y] ='.'; $         } -  -DFS (cnt+1, tot); -     } A } +  the intMainvoid)//ZOJ 1002/hdoj 1045 Fire Net - { $     //freopen ("zoj_1002.in", "R", stdin); the  the      while(SCANF ("%d", &n) = =1&&N) the     { the          for(intI=0; i<n; ++i) -scanf ("%s", &g[i]); in  theAns =-1; DFS (0,0); the  Aboutprintf ("%d\n", ans); the     } the  the     return 0; + } -  the /*Bayi 5 the 1 the 5 - 2 - 4 the */

DFS ZOJ 1002/hdoj 1045 Fire Net

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.