https://ac.nowcoder.com/acm/contest/903/L
题意:给n*n方格,0-9;起点任意,上下左右走,组成一个数值;问最小没出现的数;n<=50;
思路:好像是数值是不会超出1e6.............然后就直接dfs枚举每个数,再找没出现的;
大胆猜!!
#include<algorithm>
#include<set>
#include<queue>
#include<cmath>
#include<cstring>
#include<iostream>
#include<set>
#include<vector>
#include<queue>
#include<cmath>
#include<cstdio>
#include<map>
#include<stack>
#include<string>
#include<bits/stdc++.h>
using namespace std;
#define sfi(i) scanf("%d",&i)
#define pri(i) printf("%d\n",i)
#define sff(i) scanf("%lf",&i)
#define ll long long
#define ull unsigned long long
#define mem(x,y) memset(x,y,sizeof(x))
#define INF 0x3f3f3f3f
#define eps 1e-16
#define PI acos(-1)
#define lowbit(x) ((x)&(-x))
#define zero(x) (((x)>0?(x):-(x))<eps)
#define fl() printf("flag\n")
#define MOD(x) ((x%mod)+mod)%mod
#define endl '\n'
#define pb push_back
#define lson rt<<1,l,mid
#define rson rt<<1|1,mid+1,r
#define FAST_IO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
const int maxn=1e6+9;
const int mod=1e9+7;
inline ll read()
{
ll f=1,x=0;
char ss=getchar();
while(ss<'0'||ss>'9')
{
if(ss=='-')f=-1;ss=getchar();
}
while(ss>='0'&&ss<='9')
{
x=x*10+ss-'0';ss=getchar();
} return f*x;
}
int n;
int g[58][58];
map<int,bool>num;
void dfs(int x,int y,int step,int sum)
{
if(step<=0) return ;
num[sum]=1;
if(x-1>=1) dfs(x-1,y,step-1,sum*10+g[x-1][y]);
if(x+1<=n) dfs(x+1,y,step-1,sum*10+g[x+1][y]);
if(y-1>=1) dfs(x,y-1,step-1,sum*10+g[x][y-1]);
if(y+1<=n) dfs(x,y+1,step-1,sum*10+g[x][y+1]);
}
int main()
{
//FAST_IO;
//freopen("input.txt","r",stdin);
cin>>n;
for(int i=1;i<=n;i++)
{
for(int j=1;j<=n;j++)
{
cin>>g[i][j];
}
}
for(int i=1;i<=n;i++)
{
for(int j=1;j<=n;j++)
{
dfs(i,j,6,g[i][j]);
}
}
for(int i=0;i<=maxn;i++)
{
if(!num[i])
{
cout<<i<<endl;
break;
}
}
return 0;
}