Code Chef MINPOLY(计算几何+dp)

题面

传送门

题解

我们枚举这个凸多边形\(y\)坐标最小的点\(p_i\),然后对于所有\(y\)坐标大于等于它的点极角排序

我们预处理出\(s_{j,k}\)表示三角形\(p_i,p_j,p_k\)内部的点的\(b\)总和(不包括边界),然后记\(dp_{i,j,k}\)表示这个凸多边形之前两个点是\(p_i,p_j\),还需要\(k\)个点,最小的\(b\)是多少,然后可以直接记忆化搜索

//minamoto
#include<bits/stdc++.h>
#define R register
#define inline __attribute__((always_inline))
#define fp(i,a,b) for(R int i=(a),I=(b)+1;i<I;++i)
#define fd(i,a,b) for(R int i=(a),I=(b)-1;i>I;--i)
#define go(u) for(int i=head[u],v=e[i].v;i;i=e[i].nx,v=e[i].v)
template<class T>inline bool cmax(T&a,const T&b){return a<b?a=b,1:0;}
template<class T>inline bool cmin(T&a,const T&b){return a>b?a=b,1:0;}
using namespace std;
const int N=55,inf=0x3f3f3f3f;
typedef long long ll;
struct Point{
	int x,y,v;
	inline Point(){}
	inline Point(R int xx,R int yy,R int vv):x(xx),y(yy),v(vv){}
	inline Point operator +(const Point &b)const{return Point(x+b.x,y+b.y,v);}
	inline Point operator -(const Point &b)const{return Point(x-b.x,y-b.y,v);}
	inline ll operator *(const Point &b)const{return 1ll*x*b.y-1ll*y*b.x;}
	inline ll norm(){return 1ll*x*x+1ll*y*y;}
}p[N],c;
inline bool Right(const Point &a,const Point &b,const Point &c){return (c-a)*(b-a)>0;}
inline bool in(const Point &a,const Point &b,const Point &c,const Point &d){
	return Right(a,d,b)&&Right(b,d,c)&&Right(c,d,a);
}
inline bool cmpy(const Point &a,const Point &b){return a.y>b.y||(a.y==b.y&&a.x>b.x);}
inline bool cmpp(const Point &a,const Point &b){
	R ll k=(a-c)*(b-c);
	return k?k<0:(a-c).norm()<(b-c).norm();
}
int f[N][N][N],s[N][N],ans[N],n,ed,ttt;
int solve(int las,int now,int cnt){
	if(!cnt)return 0;if(~f[las][now][cnt])return f[las][now][cnt];
	int res=inf;
	fp(i,now+1,ttt-1)if(Right(p[now],p[i],p[las]))cmin(res,solve(now,i,cnt-1)+p[i].v+s[now][i]);
	return f[las][now][cnt]=res;
}
int main(){
//	freopen("testdata.in","r",stdin);
	scanf("%d",&n);
	fp(i,1,n)scanf("%d%d%d",&p[i].x,&p[i].y,&p[i].v),ans[i]=inf;
	sort(p+1,p+1+n,cmpy);
	fd(t,n,1){
		memset(f,-1,sizeof(f));
		c=p[t],sort(p+1,p+t,cmpp),ttt=t;
		fp(i,1,t-1)fp(j,i+1,t-1){
			s[i][j]=0;
			fp(k,i+1,j-1)if(in(c,p[j],p[i],p[k])||(p[k]-c)*(p[j]-c)==0)s[i][j]+=p[k].v;
		}
		for(R int i=1,v=0;i<t;++i){
			v=((p[i]-c)*(p[i-1]-c)==0?v:0)+p[i].v;
			fp(cnt,3,t)cmin(ans[cnt],c.v+v+solve(t,i,cnt-2));
		}
		sort(p+1,p+t,cmpy);
	}
	fp(i,3,n)printf("%d%c",ans[i]>1e7?-1:ans[i]," \n"[i==n]);
	return 0;
}
posted @ 2019-04-21 16:42  bztMinamoto  阅读(225)  评论(0编辑  收藏  举报
Live2D