zoj 3537 Cake(区间DP+最优三角形剖分)待续
来源:互联网 发布:数控铣削加工编程实例 编辑:程序博客网 时间:2024/05/02 23:08
1、http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=4472
2、题目大意;
给出一个多边形,将这个多边形用不相交的线段分割成一个一个的三角形,如果不能进行分割输出I can't cut.,每条分割线的代价是|xi + xj| * |yi + yj| % p,求将该多边形分割成三角形的最小代价是多少?
首先判断一下该多边形是不是凸多边形,如果是才能进行分割,如果不是直接返回I can't cut
dp[i][j]表示以i-j为基边的凸多边形分割成三角形的最小代价,
dp[i][j]=min(dp[i][k]+dp[k][j]+cost[i][k]+cost[k][j])
思路参考博客http://blog.csdn.net/woshi250hua/article/details/7824433
3、AC代码:
#include<stdio.h>#include<string.h>#include<algorithm>using namespace std;#define N 305#define INF 0x7ffffff int n,m;struct node{ int x; int y;}p[N];node save[N];int dp[N][N];int cost[N][N];bool cmp(const node& a,const node &b){if(a.y == b.y)return a.x < b.x;return a.y < b.y;}int xmult(node p1,node p2,node p0){return (p1.x-p0.x)*(p2.y-p0.y)-(p2.x-p0.x)*(p1.y-p0.y);}int Graham(node *p,int n) {int i;sort(p,p + n,cmp);save[0] = p[0];save[1] = p[1];int top = 1;for(i = 0;i < n; i++){while(top && xmult(save[top],p[i],save[top-1]) >= 0)top--;save[++top] = p[i];}int mid = top;for(i = n - 2; i >= 0; i--){while(top>mid&&xmult(save[top],p[i],save[top-1])>=0)top--;save[++top]=p[i];}return top;}int DP(int l,int r){ // printf("diaoyong %d %d\n",l,r); if(dp[l][r]) return dp[l][r]; if(r-l<=2) return 0; int ans=INF; for(int i=l+1;i<r;i++) { ans=min(ans,DP(l,i)+DP(i,r)+cost[l][i]+cost[i][r]); } // printf("return %d %d %d\n",l,r,ans); return dp[l][r]=ans;}int Count(node a,node b) {return (abs(a.x + b.x) * abs(a.y+b.y)) % m;}int main(){ while(scanf("%d%d",&n,&m)!=EOF) { for(int i=0;i<n;i++) scanf("%d%d",&p[i].x,&p[i].y); if(n<=3) { printf("0\n"); continue; } if(Graham(p,n)<n) printf("I can't cut.\n"); else { memset(dp,0,sizeof(dp)); memset(cost,0,sizeof(cost)); for(int i=0;i<n;i++) { for(int j=i+2;j<n;j++) { cost[i][j]=cost[j][i]=Count(save[i],save[j]); //printf("cost[%d][%d]=%d\n",i,j,cost[i][j]); } } printf("%d\n",DP(0,n-1)); } } return 0;}/*3 3 0 0 1 1 0 24 100 0 0 1 0 0 1 1 14 100 0 0 3 0 0 3 1 1 */
0 0
- zoj 3537 Cake(区间DP+最优三角形剖分)待续
- Zoj 3537 Cake (区间DP_最优三角形剖分)
- zoj 3537 cake 切蛋糕 区间DP+凸包+递归 最优三角形剖分
- zoj 3537 cake (区间DP+凸包+ 最优三角形剖分模型)
- zoj 3537 Cake (区间DP x 最优三角形剖分)
- ZOJ-3537 Cake(区间dp+凸包最优三角形剖分)
- Zoj 3537 Cake (DP最优三角形剖分)
- Zoj 3537 Cake (DP_最优三角形剖分)
- Zoj 3537 Cake (DP_最优三角形剖分)
- ZOJ - 3537 Cake (凸包+区间DP+最优三角剖分)
- zoj 3537 Cake 【凸包 + 区间dp】 【最优三角剖分】
- ZOJ 3537-Cake(凸包+最优三角刨分+区间DP)
- zoj 3537 Cake (凸包 最优三角剖分)
- ZOJ 3537 Cake 计算几何+区间dp
- zoj3537 Cake 最优三角剖分(DP)
- zoj 3537 Cake (凸包判定+区间dp)
- ZOJ 3537 Cake(凸包+区间DP)
- ZOJ 3537 Cake 凸包+区间DP+记忆化搜索
- zookeeper工作原理
- 父 shell,子 shell ,export 与 变量传递
- http协议请求响应详解
- 利用区域协方差:Structure-Preserving Image Smoothing via Region Covariances
- ls -l文件类型
- zoj 3537 Cake(区间DP+最优三角形剖分)待续
- Oracle 表空间管理维护
- windows系统调用
- innerHTML中script脚本不执行的问题
- android binder机制之——(我是binder实例)
- 菜鸟也来学习ORACLE(1)_linux下安装oracle 11g
- ubuntu 下软件安装
- ubuntu 12.04 使用随记
- win删除grub引导