dfs样例过了全wa,不知道为什么,球球!!
查看原帖
dfs样例过了全wa,不知道为什么,球球!!
1353229
wy172楼主2024/8/12 12:47
#include <iostream>
#include <algorithm>
#include<vector>
#include<cstring>
using namespace std;
typedef long long ll;
const ll INF = 100001;
int n,m,ans;
char c[505][505];

bool check(int x,int y)
{
    if(c[x][y]=='0' && c[x+1][y] == '*' && c[x-1][y] == '*' && c[x][y-1] == '*' && c[x][y+1] == '*')
        return true;
    return false;
}

void dfs(int x,int y)
{
    if(y>m)
    {
        y=1;
        x++;
    }
    if(x>n)
    {
        cout<<ans;
        return;
    }
    if(x > 1 && y > 1 && x < n && y < m && check(x,y))
    {
        ans++;
    }
    dfs(x,y+1);
}


int main()
{
    cin>>n>>m;

    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=m;j++)
        {
            char temp;
            cin>>temp;
            c[i][j]=temp;
        }
    }
    dfs(1,1);
    return 0;
}
2024/8/12 12:47
加载中...