BZOJ2087 [Poi2010]Sheep

预处理出哪两个点之间是可以划的,枚举一个端点,把所有点按时针排序,排序可以用叉积算,然后扫一遍即可

然后区间dp即可,f[i][j]=sigma f[i][k]*f[k][j](ik和kj都可以划)

#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;
#define MAXN 610
#define MAXM 20010
#define INF 1000000000
#define MOD 1000000007
#define eps 1e-8
#define ll long long
char xB[1<<15],*xS=xB,*xT=xB;
#define getc() (xS==xT&&(xT=(xS=xB)+fread(xB,1,1<<15,stdin),xS==xT)?0:*xS++)
inline int read()
{
int x=0,f=1;char ch=getc();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getc();}
while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getc();}
return x*f;
}
struct pt{
	int x;
	int y;
	pt(){
		
	}
	pt(int _x,int _y){
		x=_x;
		y=_y;
	}
	friend pt operator -(pt x,pt y){
		return pt(x.x-y.x,x.y-y.y);
	}
	friend int operator *(pt x,pt y){
		return x.x*y.y-x.y*y.x;
	}
};
int mod;
int n,m;
pt a[MAXN],b[MAXM];
bool abl[MAXN][MAXN];
int f[MAXN][MAXN];
bool vis[MAXN][MAXN];
pt now;
bool operator <(pt x,pt y){
	return (x-now)*(y-now)<0;
}
int main(){
	int i,j,k;
	scanf("%d%d%d",&n,&m,&mod);
	for(i=1;i<=n;i++){
		a[i].x=read();
		a[i].y=read();
	}
	for(i=1;i<=m;i++){
		b[i].x=read();
		b[i].y=read();
	}
	for(i=1;i<=n;i++){
		now=a[i];
		sort(b+1,b+m+1);
		int t=0;
		int wzh=1;
		for(j=i+1;j<=n;j++){
			while(wzh<=m&&(b[wzh]-now)*(a[j]-now)<=0){
				t++;
				wzh++;
			}
			if(!((t&1)||(t&&(b[wzh-1]-now)*(a[j]-now)==0))){
				abl[j][i]=abl[i][j]=1;
			}
		}
	}
	//*
	for(i=1;i


你可能感兴趣的:(BZOJ,DP,递推)