# 「NOIp2017」奶酪-记忆化搜索

### Code

```#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
using namespace std;
const int maxn=1000+5;
int book[maxn];
int T;
int n,h,r;
bool ans=false;
struct node{
int x;
int y;
int z;
int flag;//此处的flag是一个标志位，标记该点能否作为起点，避免不必要的搜索
}a[maxn];
inline int dist(node a,node b){
double tmp=sqrt((double)pow(a.x-b.x,2)+(double)pow(a.y-b.y,2)+(double)pow(a.z-b.z,2));
return tmp<=2*r;
}
void dfs(node t,int step){
book[step-1]=1;
if(t.z+r>=h){
ans=true;
return;
}
for(int i=1;i<=n;i++){
if(!book[i] && dist(a[i],t)) dfs(a[i],i+1);
if(ans) return;
}
}
bool cmp(node x,node y){
return x.z<=y.z;
}
int main(){
scanf("%d",&T);
while(T){
scanf("%d%d%d",&n,&h,&r);
for(int i=1;i<=n;i++){
scanf("%d%d%d",&a[i].x,&a[i].y,&a[i].z);
if(abs(a[i].z)<=r) a[i].flag=1;
else a[i].flag=0;
}
sort(a+1,a+n+1,cmp);
memset(book,0,sizeof(book));
ans=false;
for(int i=1;i<=n;i++){
if(a[i].flag) dfs(a[i],i+1);
if(ans) break;
}
if(ans){
printf("Yes\n");
}else printf("No\n");
T--;
}
return 0;
}```