a+b我过了!!!!!

ykj12 2022-09-01 12:53:38 1
#include <bits/stdc++.h>
using namespace std;
const int N = 1e4 + 10;
int a, b;
int x[N][N], vis[N][N];
int ans = 1000000;
int dx[] = { 0, 1, 0, -1 }, dy[] = { 1, 0, -1, 0 };
void dfs(int x, int y, int sum) {
    if (sum > ans)
        return;
    if (x == a and y == b) {
        ans = min(sum, ans);
        return;
    }
    for (int i = 0; i < 4; i++) {
        int nx, ny;
        nx = x + dx[i];
        ny = y + dy[i];
        if (nx >= 1 and ny >= 1 and nx <= a and ny <= b and vis[nx][ny] == 0) {
            vis[nx][ny] = 1;
            dfs(nx, ny, sum + 1);
        }
    }
}
int main() {
    scanf("%d%d", &a, &b);
    dfs(1, 1, 1);
    printf("%d\n", ans + 1);
    return 0;
}
{{ vote && vote.total.up }}