zoukankan      html  css  js  c++  java
  • HDU 1045 Fire Net

    传送门;http://acm.hdu.edu.cn/showproblem.php?pid=1045

     解题思路:

    1. 暴搜.

    实现代码:

     1 #include <iostream>
     2 #include <cstdio>
     3 #include <cstring>
     4 #include <cstdlib>
     5 #include <algorithm>
     6 using namespace std;
     7 
     8 const int MAXN=5;
     9 char mp[MAXN][MAXN];
    10 int ans=0;
    11 int N;
    12 bool judge(int row,int col){
    13     for(int i=col-1;i>=0;i--){
    14         if(mp[row][i]=='M') return false;
    15         if(mp[row][i]=='X') break;
    16     }
    17 
    18     for(int i=row-1;i>=0;i--){
    19         if(mp[i][col]=='M') return false;
    20         if(mp[i][col]=='X') break;
    21     }
    22     return true;
    23 }
    24 
    25 void dfs(int n,int num){
    26     if(n==N*N){
    27         ans=max(ans,num);
    28         return ;
    29     }
    30 
    31     int col=n%N;
    32     int row=n/N;
    33 
    34     if(mp[row][col]=='.'&&judge(row,col)){
    35         mp[row][col]='M';
    36         dfs(n+1,num+1);
    37         mp[row][col]='.';
    38     }
    39     dfs(n+1,num);
    40 }
    41 
    42 int main(){
    43 
    44     while(scanf("%d",&N)&&N){
    45         for(int i=0;i<N;i++){
    46             scanf("%s",mp[i]);
    47         }
    48         ans=0;
    49         dfs(0,0);
    50         printf("%d
    ",ans);
    51 
    52     }
    53 }
    自己选的路,跪着也要把它走完------ACM坑
  • 相关阅读:
    Django(四)
    Django(三)
    Django(二)
    Django 基础篇
    jQuery
    JDK,JRE,JVM区别与联系
    webdriver API中文文档
    selenium及webdriver的原理
    JAVA IO流结构图
    抽象工厂与工厂方法的区别
  • 原文地址:https://www.cnblogs.com/IKnowYou0/p/6547508.html
Copyright © 2011-2022 走看看