HDU 3516 四边形优化 解题报告
来源:互联网 发布:手机pdf语音朗读软件 编辑:程序博客网 时间:2024/05/16 07:02
Tree Construction
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 1369 Accepted Submission(s): 760
Problem Description
Consider a two-dimensional space with a set of points (xi, yi) that satisfy xi < xj and yi > yj for all i < j. We want to have them all connected by a directed tree whose edges go toward either right (x positive) or upward (y positive). The figure below shows an example tree.
Write a program that finds a tree connecting all given points with the shortest total length of edges.
Input
The input begins with a line that contains an integer n (1 <= n <= 1000), the number of points. Then n lines follow. The i-th line contains two integers xi and yi (0 <= xi, yi <= 10000), which give the coordinates of the i-th point.
Output
Print the total length of edges in a line.
Sample Input
5
1 5
2 4
3 3
4 2
5 1
1
10000 0
Sample Output
12
0
【解题报告】
四边形优化
http://download.csdn.net/detail/onepointo/9846259
代码如下:
#include<cstdio> #include<cstring> #include<algorithm> using namespace std; #define INF 0x3f3f3f3fint x[1005],y[1005],s[2005][2005],dp[2005][2005];int n,i,j,k,l,ans; int main(){ while(scanf("%d",&n)!=EOF) { memset(dp,INF,sizeof(dp)); for(i=1;i<=n;i++) { scanf("%d%d",&x[i],&y[i]); dp[i][i]=dp[i+n][i+n]=0; s[i][i]=i,s[i+n][i+n]=i+n; } for(l=2;l<=2*n;l++) { for(i=1;i<=2*n-l+1;++i) { j=i+l-1; for(k=s[i][j-1];k<=s[i+1][j];++k) { if(dp[i][j]>dp[i][k]+dp[k+1][j]+(y[k]-y[j])+(x[k+1]-x[i])) { dp[i][j]=dp[i][k]+dp[k+1][j]+(y[k]-y[j])+(x[k+1]-x[i]); s[i][j]=k; } } } } printf("%d\n",dp[1][n]); } return 0; }
让我看到你们的双手
- HDU 3516 四边形优化 解题报告
- hdu 3516 四边形优化dp
- HDU 3516 Tree Construction (四边形优化DP)
- hdu 3516 dp+四边形不等式优化
- hdu 3516 Tree Construction(四边形优化)
- Tree Construction - HDU 3516 四边形不等式优化
- HDU - 3516 Tree Construction(四边形优化)
- hdu 3516 Tree Construction 四边形不等式优化
- hdu 3516 Tree Construction (四边形优化)
- hdu 3516(四边形优化dp)
- hdu 四边形优化dp
- 四边形不等式优化dp应用------pku 1160 post office 解题报告
- 书的复制 解题报告(动态规划dp四边形不等式优化)
- HDU 3045 DP斜率优化 解题报告
- HDU 3507 DP斜率优化 解题报告
- HDU 3480 DP斜率优化 解题报告
- HDU 2829 DP斜率优化 解题报告
- hdu3480 四边形不等式DP 解题报告
- 第20课:大数据性能调优的本质和Spark性能调优要点分析
- vc2015 Crypto++ aes加密算法实现
- 计算总分
- Hdu 1520 树形DP 解题报告
- html设置单元格边框颜色
- HDU 3516 四边形优化 解题报告
- 物理环境下安装Centos+Openstack Makita
- ubuntu 安装jdk 的两种方式:
- Ubuntu系统,安装了一套eclipse+jdk+SDK的Android
- Sqlserver日期函数datepart
- html设置单元格亮边框颜色
- NYOJ-一笔画问题(并查集+欧拉回路)
- git常用命令小结
- BZOJ4843 [Neerc2016]Expect to Wait