为啥dfs爆空间?
查看原帖
为啥dfs爆空间?
567034
OceanBrawl楼主2022/2/8 22:28

rt

#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define ewen using
#define ak namespace
#define ioi std
#define ewen_ak_ioi return 0;
ewen ak ioi;
ll in(){
    char c = getchar();
    int x = 0, f = 1;
    for (; c < '0' || c > '9'; c = getchar())
        if (c == '-') f = -1;
    for (; c >= '0' && c <= '9'; c = getchar())
        x = (x << 1) + (x << 3) + (c ^ 48);
    return x * f;
}
void put(int x){
    if (x < 0) x = -x, putchar('-');
    if (x > 9) put(x / 10);
    putchar(x % 10 + '0');
}
ll a,b;
void dfs(int x)
{
    if(x==a+b)
    {
        put(x);
        return;
    }
    if(x>a+b)dfs(x-1);
    else dfs(x+1);
    return;
}
int main()
{
    a=in();b=in();
    dfs(0);
    ewen_ak_ioi
}

2022/2/8 22:28
加载中...