hdu 4665 搜索

时间:2021-07-02 14:49:39

思路:直接搜索

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
int belong[],num[],n;
int dfs(int s,int pre,int cur)
{
int i,j;
if(cur==n/)
return ;
for(i=s;i<=n;i++)
{
if(belong[i]==-)
{
belong[i]=;
for(j=i+;j<=n;j++)
if(belong[j]==-&&num[i]==num[j]&&j>pre)
{
belong[j]=;
if(dfs(s+,j,cur+))
return ;
belong[j]=-;
}
belong[i]=-;
break;
}
}
return ;
}
int main()
{
int t,i,j;
scanf("%d",&t);
while(t--)
{
memset(belong,-,sizeof(belong));
scanf("%d",&n);
for(i=;i<=n;i++)
scanf("%d",num+i);
dfs(,,);
for(i=;i<=n;i++)
printf("%d",belong[i]);
printf("\n");
}
return ;
}