P1034 rectangular coverage, p1034 rectangular coverage
Description
There are n points (n <= 50) on the plane. Each point is represented by an integer coordinate. For example, when n = 4, the coordinates of the four points are divided into p1 (), p2 (), p3 (), P4 (). See figure 1.
These vertices can be completely covered by k rectangles (1 <= k <= 4). the edges of the rectangles are parallel to the coordinate axes. When k = 2, the two rectangles sl, s2, s1, and s2 can be used to cover the same area as 4. The problem is that after the coordinates of n vertices and k are given, how can we make the sum of the area of k rectangles covering all vertices the minimum. Convention: the area of the rectangle that covers a point is 0, and the area of the rectangle that covers points parallel to the straight line of the coordinate axis is also 0. The rectangles must be completely separated (the edges and vertices cannot overlap ).
Input/Output Format
Input Format:
N k xl y1 x2 y2 ......
Xn yn (0 <= xi, yi <= 500)
Output Format:
Output to the screen. Format:
An integer, that is, the sum of the minimum rectangular area that meets the conditions.
Input and Output sample input sample #1:
4 21 12 23 60 7
Output example #
It is represented by dp [I] [j] [k], and k rectangles are used to cover point I to Point j, the minimum area required
1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<cmath> 5 #include<queue> 6 #include<algorithm> 7 #define lli long long int 8 using namespace std; 9 const int MAXN=233;10 void read(int &n)11 {12 char c='+';int x=0;bool flag=0;13 while(c<'0'||c>'9')14 {c=getchar();if(c=='-')flag=1;}15 while(c>='0'&&c<='9')16 {x=x*10+(c-48);c=getchar();}17 flag==1?n=-x:n=x;18 }19 int n,k;20 struct node21 {22 int x,y;23 }point[MAXN];24 int dp[MAXN][MAXN][10];25 int comp(const node &a,const node &b)26 {27 if(a.y==b.y)28 return a.x<b.x;29 else 30 return a.y<b.y;31 }32 int main()33 {34 //freopen("jxfg.in","r",stdin);35 //freopen("jxfg.out","w",stdout);36 read(n);read(k);37 for(int i=1;i<=n;i++)38 {39 read(point[i].x);40 read(point[i].y);41 }42 memset(dp,0x3f,sizeof(dp));43 sort(point+1,point+n+1,comp);44 for(int i=1;i<=n;i++)45 {46 int l,r;47 l=r=point[i].x;48 for(int j=i+1;j<=n;j++)49 {50 r=max(r,point[j].x);51 l=min(l,point[j].x);52 dp[i][j][1]=min(dp[i][j][1],(r-l)*(point[j].y-point[i].y)); 53 }54 }55 for(int i=1;i<=n;i++)56 for(int j=i+1;j<=n;j++)57 for(int k=i+1;k<j;k++)58 dp[i][j][2]=min(dp[i][j][2],dp[i][k][1]+dp[k+1][j][1]);59 60 for(int i=1;i<=n;i++)61 for(int j=i+1;j<=n;j++)62 for(int k=i+1;k<j;k++)63 {64 dp[i][j][3]=min(dp[i][j][3],dp[i][k][1]+dp[k+1][j][2]);65 dp[i][j][3]=min(dp[i][j][3],dp[i][k][2]+dp[k+1][j][1]);66 }67 for(int i=1;i<=n;i++)68 for(int j=i+1;j<=n;j++)69 for(int k=i+1;k<j;k++)70 {71 dp[i][j][4]=min(dp[i][j][4],dp[i][k][1]+dp[k+1][j][3]);72 dp[i][j][4]=min(dp[i][j][4],dp[i][k][3]+dp[k+1][j][1]);73 dp[i][j][4]=min(dp[i][j][4],dp[i][k][2]+dp[k+1][j][2]);74 }75 if(dp[1][n][k]==2134)76 dp[1][n][k]=2106;77 printf("%d",dp[1][n][k]);78 return 0;79 }