题意:

给出平面上n个点的坐标,选k个点,使得这k个点围起来的面积最大.

分析:

参考了 叉姐的分析不慌不忙菊苣的代码

思路我都懂,但是DP的部分还是不太会写.

我体会了一下其中含义,也许这样可能会好理解一点:

因为求出来的凸包的点数是固定的,所能选的点数也是固定的,那么不选的点的数量也是固定的.

可以反过来考虑:少选一个点,就要损失凸包上的一块面积.

假设\(d(i,j)\)表示考虑了前\(i\)个点,选了\(j\)个点,所损失的最少面积.

第\(i\)个点的前一个点是\(i'\),损失的面积为\(S_{cut}\),那么\(d(i,j)=min(d(i,j),d(i',j-1)+S_{cut})\)

最后答案就是凸包总面积减去最后损失的最小面积.

损失的面积是一小块一小块三角形累加起来的.

上个图片仅供参考:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
using namespace std; typedef long long LL; const int maxn = 100 + 10; struct Point
{
LL x, y;
Point(LL x = 0, LL y = 0) : x(x), y(y) {}
void read() { scanf("%lld%lld", &x, &y); }
}; Point operator - (const Point& A, const Point& B) {
return Point(A.x - B.x, A.y - B.y);
} bool operator < (const Point& A, const Point& B) {
return A.x < B.x || (A.x == B.x && A.y < B.y);
} LL Cross(const Point& A, const Point& B) {
return A.x * B.y - A.y * B.x;
} vector<Point> p, con; vector<Point> ConvexHull() {
sort(p.begin(), p.end());
int n = p.size();
vector<Point> ch(n);
int m = 0;
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;
} int n, k; LL d[maxn][maxn];
bool vis[maxn]; int main()
{
//freopen("in.txt", "r", stdin); int _; scanf("%d", &_);
for(int __ = 1; __ <= _; __++) {
scanf("%d%d", &n, &k);
p.resize(n);
for(int i = 0; i < n; i++) p[i].read(); con = ConvexHull();
int sz = con.size();
if(sz <= 2 || k <= 2) { printf("0\n"); continue; } LL totarea = 0;
for(int i = 2; i < sz; i++) totarea += Cross(con[i-1]-con[0], con[i] - con[0]); if(k >= sz) {
printf("%lld\n", totarea);
continue;
} LL ans = 0x3f3f3f3f3f3f3f3f;
memset(vis, false, sizeof(vis));
int times = min(10 * n / k, sz);
while(times--) {
int s = rand() % sz;
while(vis[s]) s = rand() % sz;
vis[s] = true; memset(d, 0x3f, sizeof(d));
d[0][0] = 0;
for(int i = 1; i <= sz; i++) {
int p0 = (s + i) % sz;
LL cut = 0;
for(int j = i - 1; j >= 0; j--) {
int p2 = (s + j) % sz;
int p1 = (p2 + i) % sz;
cut += Cross(con[p1] - con[p0], con[p2] - con[p0]);
for(int l = k; l > 0; l--)
d[i][l] = min(d[i][l], d[j][l-1] + cut);
}
}
ans = min(ans, d[sz][k]);
} printf("Case #%d: %lld\n", __, totarea - ans);
} return 0;
}

HDU 5473 There was a kingdom 凸包 DP的更多相关文章

  1. hdu 5025 Saving Tang Monk 状态压缩dp+广搜

    作者:jostree 转载请注明出处 http://www.cnblogs.com/jostree/p/4092939.html 题目链接:hdu 5025 Saving Tang Monk 状态压缩 ...

  2. HDU 3016 Man Down (线段树+dp)

    HDU 3016 Man Down (线段树+dp) Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Ja ...

  3. HDU 3341 Lost's revenge AC自动机+dp

    Lost's revenge Time Limit: 15000/5000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others)T ...

  4. HDU 2457 DNA repair(AC自动机+DP)题解

    题意:给你几个模式串,问你主串最少改几个字符能够使主串不包含模式串 思路:从昨天中午开始研究,研究到现在终于看懂了.既然是多模匹配,我们是要用到AC自动机的.我们把主串放到AC自动机上跑,并保证不出现 ...

  5. Codeforces 835 F Roads in the Kingdom(树形dp)

    F. Roads in the Kingdom(树形dp) 题意: 给一张n个点n条边的无向带权图 定义不便利度为所有点对最短距离中的最大值 求出删一条边之后,保证图还连通时不便利度的最小值 $n & ...

  6. HDU 1028 Ignatius and the Princess III dp整数划分

    http://acm.hdu.edu.cn/showproblem.php?pid=1028 dp[i][j]表示数值为i,然后最小拆分的那个数是j的时候的总和. 1 = 1 2 = 1 + 1 . ...

  7. HDU 1025 Constructing Roads In JGShining's Kingdom(DP+二分)

    点我看题目 题意 :两条平行线上分别有两种城市的生存,一条线上是贫穷城市,他们每一座城市都刚好只缺乏一种物资,而另一条线上是富有城市,他们每一座城市刚好只富有一种物资,所以要从富有城市出口到贫穷城市, ...

  8. hdu 1025:Constructing Roads In JGShining's Kingdom(DP + 二分优化)

    Constructing Roads In JGShining's Kingdom Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65 ...

  9. HDU 1025 Constructing Roads In JGShining&#39;s Kingdom (DP)

    Problem Description JGShining's kingdom consists of 2n(n is no more than 500,000) small cities which ...

随机推荐

  1. Bootcamp Win10蓝牙鼠标的问题

    运行services.msc找到Bluetooth support service 把启动类型从手动改为自动 重新连接蓝牙鼠标

  2. Java thymeleaf模板获取资源文件的内容

    我们在某些时候可能需要获取配置文件properties中的配置信息,而不需要用Java传给模板,在模板中就可以直接获取 我们需要在resources/下定义国际化配置文件即可,注意名称必须中messa ...

  3. C# 实现本地化日志管理

    1.新建一个类库解决方案 CommnoLog 2.新建两个文件夹 2.1FileUtil.cs  代码如下 public static class FileUtil { /// <summary ...

  4. Kendo UI 单页面应用(四) Layout

    Kendo UI 单页面应用(四) Layout Layout 继承自 View,可以用来包含其它的 View 或是 Layout.下面例子使用 Layout 来显示一个 View <div i ...

  5. HDU 3001 Travelling (状压DP,3进制)

    题意: 给出n<=10个点,有m条边的无向图.问:可以从任意点出发,至多经过同一个点2次,遍历所有点的最小费用? 思路: 本题就是要卡你的内存,由于至多可经过同一个点2次,所以只能用3进制来表示 ...

  6. win10 KMS激活

    运行 输入以管理员权限输入CMD 如果已安装密匙先卸载,没有的话可以跳过 slmgr -upk 卸载密匙命令 输入对应版密匙以及KMS地址激活 1.键入命令:slmgr -ipk XXXXX-XXXX ...

  7. MyEclipse Update Progress Error解决方法

    MyEclipse Update Progress Error现象:频繁弹出Update Progress(Time of error:……)窗口..log文件里 org.eclipse.swt.SW ...

  8. Vue中使用computed与watch结合实现数据变化监听

    目的:当数据变化时,为其中重要数据增加边框,实现闪烁以达到提醒目的.数据格式如下,只有在未处理火警/故障时增加闪烁边框.可以使用watch进行深度监听.数据格式已定,也非常明确要监听的数据是有两个.既 ...

  9. JS函数的length属性

    length 是函数对象的一个属性值,指该函数有多少个必须要传入的参数,那些已定义了默认值的参数不算在内,比如function(xx = 0)的length是0.. 另外在函数内部:arguments ...

  10. Kafka 完全分布式集群环境搭建

    思路: 先在主机s1上安装配置,然后远程复制到其它两台主机s2.s3上, 并分别修改配置文件server.properties中的broker.id属性. 1. 搭建前准备 示例共三台主机,主机IP映 ...