求代码改发
查看原帖
求代码改发
400384
fifififi楼主2022/11/16 15:36

我的做法是先转换成有向图再暴搜,T掉一半,太蒟了写不来记忆化 50分代码

#include<bits/stdc++.h>
#define max(x,y) (((x)>(y))?(x):(y))

class point{public: int x,y;} a[502];
class node{public: int v,w;};

int n,k;
int ansi;//the number of point you have got
std::vector<node> map[502];

bool compare(point x,point y) {return (x.x==y.x)?(x.y<y.y):(x.x<y.x);}

void dfs(int u,int length,int cnt)
{
	for(int i=map[u].size()-1;i>=0;i--)
		if(map[u][i].w<=k-length)
			dfs(map[u][i].v,length+map[u][i].w,cnt+1);
	ansi=max(ansi,cnt);
}

int main()
{
// 	freopen("point.in","r",stdin);
// 	freopen("point.out","w",stdout);
	scanf("%d%d",&n,&k);
	for(int i=1;i<=n;i++)
		scanf("%d%d",&a[i].x,&a[i].y);
	std::sort(a+1,a+n+1,compare);
	for(int i=1;i<n;i++)
		for(int j=n;j>i;j--)
		{
			if(a[j].y<a[i].y) continue;
			map[i].push_back(node{j,(a[j].x+a[j].y-a[i].x-a[i].y-1)});
		}
	for(int i=1;i<=n;i++)
		dfs(i,0,1);//the current point,the length,the number of point you have got
	printf("%d",k+ansi);
	return 0;
}
2022/11/16 15:36
加载中...