HDU - 3516 Tree Construction(四边形优化)
来源:互联网 发布:翻墙 for mac 编辑:程序博客网 时间:2024/05/16 12:04
题目大意:给你一系列的坐标,x递增,y递减,问如何连成一棵树,能使数边和达到最小
解题思路:用dp[i][j]表示从第i到第j个连接起来的最小和
则dp[i][j] = dp[i][k] + dp[k + 1][j] + abs(x[k + 1] - x[i] + y[k] - y[j])
#include <cstdio>#include <cstring>#define abs(x)((x)>0?(x):(-(x)))const int N = 1010;const int INF = 0x3f3f3f3f;int x[N], y[N];int dp[N][N], s[N][N];int n;void init() { for (int i = 1; i <= n; i++) { scanf("%d%d", &x[i], &y[i]); dp[i][i] = 0; s[i][i] = i; }}void solve() { for (int len = 1; len < n; len++) { for (int i = 1; i + len <= n; i++) { int j = i + len; dp[i][j] = INF; for (int k = s[i][j - 1]; k <= s[i + 1][j]; k++) if (dp[i][j] > dp[i][k] + dp[k + 1][j] + abs(x[k + 1] - x[i] + y[k] - y[j])) { dp[i][j] = dp[i][k] + dp[k + 1][j] + abs(x[k + 1] - x[i] + y[k] - y[j]); s[i][j] = k; } } } printf("%d\n", dp[1][n]);}int main() { while (scanf("%d", &n) != EOF) { init(); solve(); } return 0;}
0 0
- HDU 3516 Tree Construction (四边形优化DP)
- hdu 3516 Tree Construction(四边形优化)
- Tree Construction - HDU 3516 四边形不等式优化
- HDU - 3516 Tree Construction(四边形优化)
- hdu 3516 Tree Construction 四边形不等式优化
- hdu 3516 Tree Construction (四边形优化)
- HDU 3516 Tree Construction (四边形不等式优化DP)
- HDU 3516 Tree Construction (dp+四边形不等式优化)
- HDU-3516 Tree Construction(区间dp+四边形优化)
- hdu 3516 Tree Construction (四边形不等式优化DP)
- dp四边形优化 Hdu 3516 Tree Construction 题解
- hdu 3516 Tree construction DP+四边形不等式
- hdu 3516 Tree Construction
- hdu 3516 四边形优化dp
- hdu 3516 dp+四边形不等式优化
- HDU 3516 四边形优化 解题报告
- hdu 3516(四边形优化dp)
- hdu 四边形优化dp
- http必知必会
- Dairy of CDQZ 2
- 黑马程序员——C基础---二维数组
- 实现 用批处理获取cpu核心数 替换制定字符串
- 线程同步函数
- HDU - 3516 Tree Construction(四边形优化)
- js基础
- POJ 1042 Gone Fishing
- 整理下前一阵学的排序算法(1)
- 测试代码的编写
- 深入浅出学Shiro(一)--登录认证
- Android之简单模仿微信聊天界面
- [Linux学习]安装LNMP/LAMP一键安装包
- NSDictionary Class Reference