标签:ref maximum util esc ini alt list color cti
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 858 | Accepted: 250 |
5 3 1 6 10 10 7 9 1 2 0 0 3 2 2 5 6 8 3
1
首先在不考虑相交的情况下预处理出哪两个点可以连线,然后dp;
dp[i][j] 表示第 i 个点到第 j 个点最多可连多少条线,dp[i][j] = max(dp[i][k] + dp[k][j] + cnc[i][j], dp[i][j]);
其中 i < k < j;cnc[i][j] 表示 i , j 能否连线,能则为1,否则为0;
#include<map> #include<set> #include<list> #include<deque> #include<queue> #include<stack> #include<cmath> #include<ctime> #include<bitset> #include<cctype> #include<cfloat> #include<cstdio> #include<memory> #include<string> #include<vector> #include<cassert> #include<csignal> #include<cstdlib> #include<cstring> #include<numeric> #include<utility> #include<iostream> #include<algorithm> #include<functional> #define LL long long #define PB push_back #define MAXN 171 #define RPT(I,L,R) for(int I=L;I<R;++I) #define TPR(I,R,L) for(int I=R;I>=L;--I) using namespace std; template<class T> bool Umx(T &A,const T &B) { return B>A?A=B,1:0; } template<class T> bool Umn(T &A,const T &B) { return B<A?A=B,1:0; } const int inf=~0u>>2; int n,m,i,j,k; LL r; bool cnc[MAXN][MAXN]; int f[MAXN][MAXN]; struct point { LL x,y; bool operator < (const point &T) const { return this->y<T.y || (this->y==T.y && this->x<T.x); } void read() { scanf("%I64d%I64d",&x,&y); } } p[MAXN],c[MAXN]; inline LL sqr(LL X) { return X*X; } inline LL dot(point A,point B,point O) { return (A.x-O.x)*(B.x-O.x)+(A.y-O.y)*(B.y-O.y); } inline LL cross(point A,point B) { return A.x*B.y-B.x*A.y; } inline LL cross(point A,point B,point O) { return (A.x-O.x)*(B.y-O.y)-(B.x-O.x)*(A.y-O.y); } inline LL dist2(point A,point B) { return sqr(A.x-B.x)+sqr(A.y-B.y); } struct cmp { point O; cmp(const point &OO):O(OO) {} bool operator()(const point &A,const point &B) { return cross(A,B,O)>0; } }; void init() { memset(f,-1,sizeof f); scanf("%d%d%d",&n,&m,&r); RPT(i,0,n) p[i].read(); RPT(i,0,m) c[i].read(); sort(p,p+n); sort(p+1,p+n,cmp(p[0])); } bool CrsCcl(point A,point B,point O) { if (sqr(r)>=min(dist2(O,A),dist2(O,B))) return true; if (dot(B,O,A)<0ll || dot(A,O,B)<0ll) return false; return (double)r*r*dist2(A,B)>=(double)cross(A,B,O)*cross(A,B,O); } void Deal_Cnc() { memset(cnc,false,sizeof cnc); RPT(i,0,n) RPT(j,i+2,n) if (!(i==0 && j==n-1)) { cnc[i][j]=cnc[j][i]=true; RPT(k,0,n) if (CrsCcl(p[i],p[j],c[k])) { cnc[i][j]=cnc[j][i]=false; break; } } } int DP(int L,int R) { if (f[L][R]>0) return f[L][R]; if (R-L<2) return f[L][R]=0; else if (R-L==2) return cnc[L][R]; int res=0; RPT(i,L+1,R) Umx(res,DP(L,i)+DP(i,R)); return f[L][R]=res+cnc[L][R]; } int main() { init(); Deal_Cnc(); printf("%d\n",DP(0,n-1)); return 0; }
poj3178 Roping the Field (计算几何 + dp)
标签:ref maximum util esc ini alt list color cti
原文地址:http://www.cnblogs.com/xiepingfu/p/7287004.html