下面是别人的解题报告的链接,讲解很详细,要注意细节的处理。。。以及为什么可以这样做

http://blog.csdn.net/woshi250hua/article/details/7824433

我的代码:

 //其中求凸包用的是Andrew扫描算法,复杂度主要为排序O(n*logn),扫描为O(n)
#include <cstdio>
#include <algorithm>
#define INF 100000000
#define min(a,b) a<b?a:b;
using namespace std;
//点的定义
struct point
{
int x,y;
bool operator <(const point & other) const
{
if(x == other.x) return y < other.y;
return x < other.x;
};
} convex[];
//判断是往左还是往右
bool checkDir(point p0,point p1,point p2)
{
//往左返回true
if((p1.x-p0.x)*(p2.y-p0.y)-(p1.y-p0.y) * (p2.x-p0.x) <= )
return true;
else return false;
}
//求凸包的算法···,返回凸包的顶点数,输入的顶点数>=3。0,1,2特判,如果有需要的话
int andrew(point p[],int n)
{
sort(p,p+n);
int m=;
for(int i=; i<n; ++i)
{
while(m > && checkDir(convex[m-],convex[m-],p[i]) ) --m;
convex[m++] = p[i];
}
int k =m;
for(int i=n-; i>=; --i)
{
while(m > k && checkDir(convex[m-],convex[m-],p[i]) ) --m;
convex[m++] = p[i];
}
return m-;
}
int main()
{
// freopen("in.cpp","r",stdin);
int n,m,dp[][],cost[][];
struct point p[];
while(scanf("%d%d",&n,&m) != EOF)
{
//读入数据
for(int i=; i<n; ++i)
scanf("%d%d",&p[i].x,&p[i].y);
int num = andrew(p,n);
if(num != n)
{
printf("I can't cut.\n");
continue;
}
//预处理dp数组的值
for(int i=; i<n; ++i)
{
for(int j=; j<n; ++j)
dp[i][j] = INF;
dp[i][(i+)%n] = ;
}
//预处理cost数组的值
for(int i=; i<n; ++i)
{
cost[i][i+] = cost[i+][i] = ;
cost[i][i] =;
}
for(int i=; i<n; ++i)
for(int j=i+; j<n; ++j)
cost[j][i] = cost[i][j] = abs(convex[i].x + convex[j].x) * abs(convex[i].y+convex[j].y)%m;
//DP
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]+cost[k][i]+cost[k][j]);
printf("%d\n",dp[][n-]);
}
return ;
}

区间DP Zoj 3537 Cake 区间DP 最优三角形剖分的更多相关文章

  1. zoj 3537 Cake 区间DP (好题)

    题意:切一个凸边行,如果不是凸包直接输出.然后输出最小代价的切割费用,把凸包都切割成三角形. 先判断是否是凸包,然后用三角形优化. dp[i][j]=min(dp[i][j],dp[i][k]+dp[ ...

  2. zoj 3537 Cake(区间dp)

    这道题目是经典的凸包的最优三角剖分,不过这个题目给的可能不是凸包,所以要提前判定一下是否为凸包,如果是凸包的话才能继续剖分,dp[i][j]表示已经排好序的凸包上的点i->j上被分割成一个个小三 ...

  3. ZOJ 3537 Cake (区间DP,三角形剖分)

    题意: 给出平面直角坐标系上的n个点的坐标,表示一个多边形蛋糕,先判断是否是凸多边形,若否,输出"I can't cut.".若是,则对这个蛋糕进行3角形剖分,切n-3次变成n-2 ...

  4. zoj 3537 Cake (凸包确定+间隔dp)

    Cake Time Limit: 1 Second      Memory Limit: 32768 KB You want to hold a party. Here's a polygon-sha ...

  5. ZOJ 3537 Cake(凸包+区间DP)

    题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3537 题目大意:给出一些点表示多边形顶点的位置,如果不是凸多边形 ...

  6. 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 ...

  7. ZOJ 3537 Cake 求凸包 区间DP

    题意:给出一些点表示多边形顶点的位置(如果多边形是凹多边形就不能切),切多边形时每次只能在顶点和顶点间切,每切一次都有相应的代价.现在已经给出计算代价的公式,问把多边形切成最多个不相交三角形的最小代价 ...

  8. ZOJ - 3537 Cake (凸包+区间DP+最优三角剖分)

    Description You want to hold a party. Here's a polygon-shaped cake on the table. You'd like to cut t ...

  9. ZOJ 3905 Cake(贪心+dp)

    动态规划题:dp[i][j]表示有i个Cake,给了Alice j个,先按照b排序,这样的话,能保证每次都能成功给Alice Cake,因为b从大到小排序,所以Alice选了j个之后,Bob最少选了j ...

随机推荐

  1. FastJson之JsonObject, JsonString, JavaBean,List快速转换

    // 将json字符串转换为json对象 JSONObject jsonObject = JSON.parseObject(jsonStr); // {"retState":&qu ...

  2. English trip -- Review Unit 10 Leisure 休闲

    Words dance exercise fish play basketball play cards swim cook play the guitar listen to music watch ...

  3. Rspec: everyday-rspec实操。5:controller test(了解基础)

    第 5 章 控制器测试 5.1基础 rails generate rspec:controller home RSpec.describe HomeController, type: :control ...

  4. codeforces 494a//Treasure// Codeforces Round #282(Div. 1)

    题意:一个'('  ,  ')'  ,  '#'组成的串,可将'#'换成至少一个')'.问一个换法能使串匹配. 至少换成一个,那么就先都换成一个,记结果为str.最后一个')'的后面没有未匹配的'(' ...

  5. Confluence 6 嵌套用户组的备注

    潜在的性能影响.启用嵌套用户组可能会减慢用户查找的速度. 在 LDAP 中定义嵌套用户组.在 LDAP 中,一个嵌套用户组是 DN (Distinguished Name)的子用户组,这个字用户组将会 ...

  6. P3377 【模板】左偏树(可并堆)

    //#pragma comment(linker, "/stack:200000000") //#pragma GCC optimize("Ofast,no-stack- ...

  7. UVA-10497 Sweet Child Makes Trouble (计数+高精度)

    题目大意:这是一道简单排列组合题 .简单说下题意:n件物品,把这n件物品放到不是原来的位置,问所有的方案数.所有的位置都没有变. 题目解析:按照高中的方法,很快得到一个递推公式:f [n]= (n-1 ...

  8. HDOJ1004

    #include<iostream> #include "cstring" using namespace std; int add(char s1[],char s2 ...

  9. spring PROPAGATION

    PROPAGATION_REQUIRED Support a current transaction; create a new one if none exists.  支持一个当前事务;如果不存在 ...

  10. 阿里云ECS安装最新版本Node.js

    原文  http://www.w3ctech.com/topic/1610 主题 Node.js操作系统服务器 我的ECS实例是Ubuntu操作系统,直接使用 apt-get install node ...