zoj 3537 Cake 区间DP (好题)
题意:切一个凸边行,如果不是凸包直接输出。然后输出最小代价的切割费用,把凸包都切割成三角形。
先判断是否是凸包,然后用三角形优化。
dp[i][j]=min(dp[i][j],dp[i][k]+dp[k][j]+w[i][k]+w[j][k]);
w[i][j]代表i到j点的切割费用。
dp[i][j]:表示以i到j点的最小费用。则可把凸边行分成三个部分的费用。两个凸边行(i,k),(k,j)和两条边的费用(i,k),(j,k),k为枚举的三角形顶点。
Zoj 3537 Cake (DP_最优三角形剖分)
//#pragma comment(linker, "/STACK:167772160")//手动扩栈~~~~hdu 用c++交
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<queue>
#include<stack>
#include<cmath>
#include<set>
#include<algorithm>
#include<vector>
// #include<malloc.h>
using namespace std;
#define clc(a,b) memset(a,b,sizeof(a))
#define LL long long
const int inf = 0x3f3f3f3f;
const double eps = 1e-;
const double pi = acos(-);
// inline int r(){
// int x=0,f=1;char ch=getchar();
// while(ch>'9'||ch<'0'){if(ch=='-') f=-1;ch=getchar();}
// while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
// return x*f;
// }
const int maxn=;
struct Point{
int x, y;
Point(int x=, int y=):x(x),y(y) { }
}p[maxn]; // typedef Point Vector; int w[maxn][maxn],dp[maxn][maxn],n,m; // Vector operator + (const Vector& A, const Vector& B)
// {
// return Vector(A.x+B.x, A.y+B.y);
// }
// Vector operator - (const Point& A, const Point& B)
// {
// return Vector(A.x-B.x, A.y-B.y);
// }
// double Cross(const Vector& A, const Vector& B)
// {
// return A.x*B.y - A.y*B.x;
// } // Vector Rotate(const Vector& A, double rad)
// {
// return Vector(A.x*cos(rad)-A.y*sin(rad), A.x*sin(rad)+A.y*cos(rad));
// } // bool operator < (const Point& p1, const Point& p2)
// {
// return p1.x < p2.x || (p1.x == p2.x && p1.y < p2.y);
// } // bool operator == (const Point& p1, const Point& p2)
// {
// return p1.x == p2.x && p1.y == p2.y;
// }
// // 点集凸包
// // 如果不希望在凸包的边上有输入点,把两个 <= 改成 <
// // 如果不介意点集被修改,可以改成传递引用
// vector<Point> ConvexHull(vector<Point> p)
// {
// // 预处理,删除重复点
// sort(p.begin(), p.end());
// p.erase(unique(p.begin(), p.end()), p.end()); // int n = p.size();
// int m = 0;
// vector<Point> ch(n+1);
// for(int i = 0; i < n; i++)
// {
// while(m > 1 && Cross(ch[m-1]-ch[m-2], p[i]-ch[m-2]) <= 0) m--;
// ch[m++] = p[i];
// }
// int k = m;
// for(int i = n-2; i >= 0; i--)
// {
// while(m > k && Cross(ch[m-1]-ch[m-2], p[i]-ch[m-2]) <= 0) m--;
// ch[m++] = p[i];
// }
// if(n > 1) m--;
// ch.resize(m);
// return ch;
// }
Point save[],temp[];
int xmult(Point p1,Point p2,Point p0){ return (p1.x-p0.x)*(p2.y-p0.y)-(p2.x-p0.x)*(p1.y-p0.y);
}
bool cmp(const Point &a,const Point &b){ if(a.y == b.y)return a.x < b.x;
return a.y < b.y;
}
int Graham(Point *p,int n) {
int i;
sort(p,p + n,cmp);
save[] = p[];
save[] = p[];
int top = ;
for(i = ;i < n; i++){ while(top && xmult(save[top],p[i],save[top-]) >= )top--;
save[++top] = p[i];
}
int mid = top;
for(i = n - ; i >= ; i--){ while(top>mid&&xmult(save[top],p[i],save[top-])>=)top--;
save[++top]=p[i];
}
return top;
} int main(){
// freopen("in.txt","r",stdin);
while(~scanf("%d%d",&n,&m)){
for(int i=;i<n;i++) scanf("%d%d",&p[i].x,&p[i].y);
clc(dp,);
clc(w,);
int v;
v=Graham(p,n);
// printf("%d\n",(int)v.size());
if(v<n) printf("I can't cut.\n");
else{
for (int i = ; i < n; ++i)
for (int j = i + ; j < n; ++j)
w[i][j] = w[j][i] =(abs(save[i].x + save[j].x) * abs(save[i].y+save[j].y)) % m;
for (int i = ; i < n; ++i) {
for (int j = ; j < n; ++j)
dp[i][j] = inf;
dp[i][(i+)%n] = ;
}
for (int i = n - ; i >= ; --i)
for (int j = i + ; j < n; ++j)
for (int k = i + ; k <= j - ; ++k)
dp[i][j] = min(dp[i][j],dp[i][k]+dp[k][j]+w[i][k]+w[k][j]);
printf("%d\n",dp[][n-]);
}
}
return ;
}
zoj 3537 Cake 区间DP (好题)的更多相关文章
- zoj 3537 Cake(区间dp)
这道题目是经典的凸包的最优三角剖分,不过这个题目给的可能不是凸包,所以要提前判定一下是否为凸包,如果是凸包的话才能继续剖分,dp[i][j]表示已经排好序的凸包上的点i->j上被分割成一个个小三 ...
- 区间DP Zoj 3537 Cake 区间DP 最优三角形剖分
下面是别人的解题报告的链接,讲解很详细,要注意细节的处理...以及为什么可以这样做 http://blog.csdn.net/woshi250hua/article/details/7824433 我 ...
- 又一道区间DP的题 -- P3146 [USACO16OPEN]248
https://www.luogu.org/problemnew/show/P3146 一道区间dp的题,以区间长度为阶段; 但由于要处理相邻的问题,就变得有点麻烦; 最开始想了一个我知道有漏洞的方程 ...
- poj 2955 Brackets (区间dp基础题)
We give the following inductive definition of a “regular brackets” sequence: the empty sequence is a ...
- ZOJ 3537 Cake(凸包+区间DP)
题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3537 题目大意:给出一些点表示多边形顶点的位置,如果不是凸多边形 ...
- ZOJ 3537 Cake(凸包判定+区间DP)
Cake Time Limit: 1 Second Memory Limit: 32768 KB You want to hold a party. Here's a polygon-shaped c ...
- ZOJ 3537 Cake 求凸包 区间DP
题意:给出一些点表示多边形顶点的位置(如果多边形是凹多边形就不能切),切多边形时每次只能在顶点和顶点间切,每切一次都有相应的代价.现在已经给出计算代价的公式,问把多边形切成最多个不相交三角形的最小代价 ...
- zoj 3537 Cake (凸包确定+间隔dp)
Cake Time Limit: 1 Second Memory Limit: 32768 KB You want to hold a party. Here's a polygon-sha ...
- 状态压缩---区间dp第一题
标签: ACM 题目 Gappu has a very busy weekend ahead of him. Because, next weekend is Halloween, and he is ...
随机推荐
- SGU 186
总是拆最短的链子 连接长的链子 贪心.... #include <cstdio> #include <cstring> #include <cmath> #i ...
- Codeforces Round #242 (Div. 2) A~C
题目链接 A. Squats time limit per test:1 secondmemory limit per test:256 megabytesinput:standard inputou ...
- iOS开发的小技巧(断点打印)
iOS开发中我们会碰到这样的需求:打印沙盒目录,打印对象信息,对象信息可以通过断点查看,有时候对象属性繁多时看起来又比较麻烦. 今天学到一个比较实用的方法: 在运行时打一个断点,当程序停在这个断点后, ...
- codeforces #310 div1 B
我们考虑n-1座桥每座桥需要的长度在一个区间[L,R]中 之后我们现在有m座桥,每个桥的长度为k 题意就是要求一个匹配方案 显然如果数据范围不大直接KM就可以了 可是20w的数据KM显然要T 所以我们 ...
- thinkphp URL相关
具体详见tp文档. 此处仅做学习笔记. 后缀配置: // 模板文件后缀名 'TMPL_TEMPLATE_SUFFIX'=>'.html', // 伪静态文件后缀名 'URL_HTML_SUFFI ...
- CentOS7.1配置远程桌面
网上看了很多资料,完全是乱的. 我使用的是CentOS7.1的系统.我的要求是windows的客户机可以远程访问CentOS系统. 1,首先需要检查一下服务器是否已经安装了VNC服务,检查服务器的是否 ...
- 转:tar 常用命令
tar在linux上是常用的打包.压缩.加压缩工具,他的参数很多,折里仅仅列举常用的压缩与解压缩参数 参数: -c :create 建立压缩档案的参数: -x : 解压缩压缩档案的参数: -z : 是 ...
- 115. Distinct Subsequences
题目: Given a string S and a string T, count the number of distinct subsequences of T in S. A subseque ...
- 捉虫记2:windows程序句柄泄露的上下文环境
作为程序员,开发程序是基本功,而调试程序也是必不可少的技能之一.软件在主体功能开发完成后会经历各个阶段的测试,才会被发布.在测试过程中,出现较多的可能就是内存泄漏,句柄泄漏,异常崩溃等属于非功能型的软 ...
- Flash Builder 4.6 找不到所需的Adobe Flash Player
问题: 安装完Flash Builder 4.6 ,第一次运行项目,出现如下错误提示: “Flash Builder 找不到所需版本的 Adobe Flash Player.您可能需要安装该版本的 F ...