[BZOJ1694/1742/3074]The Cow Run 三倍经验
Description
Input
Output
* Line 1: A single integer: the minimum total staleness Bessie can achieve while eating all the clumps.
Sample Input
1
9
11
19
INPUT DETAILS:
Four clumps: at 1, 9, 11, and 19. Bessie starts at location 10.
Sample Output
OUTPUT DETAILS:
Bessie can follow this route:
* start at position 10 at time 0
* move to position 9, arriving at time 1
* move to position 11, arriving at time 3
* move to position 19, arriving at time 11
* move to position 1, arriving at time 29
giving her a total staleness of 1+3+11+29 = 44. There are other routes
with the same total staleness, but no route with a smaller one.44
// By BriMon
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
using namespace std;
inline int read(){
int res=;char ch=getchar();
while(!isdigit(ch)) ch=getchar();
while(isdigit(ch)){res=(res<<)+(res<<)+(ch^);ch=getchar();}
return res;
} int n, x;
int f[][][], pos[]; int main()
{
n = read(), x = read();
for (int i = ; i <= n ; i ++)
pos[i] = read();
sort(pos + , pos + + n);
memset(f, 0x3f, sizeof f);
for (int i = ; i <= n ; i ++) f[i][i][] = f[i][i][] = abs(x - pos[i]) * n;
for (int len = ; len <= n ; len ++)
{
for (int i = ; i <= n ; i ++)
{
int j = i + len - ;
if (j > n) break;
f[i][j][] = min(f[i][j][], min(f[i+][j][] + (n - (j - i)) * (pos[j] - pos[i]), f[i+][j][] + (n - (j - i)) * (pos[i+] - pos[i])));
f[i][j][] = min(f[i][j][], min(f[i][j-][] + (n - (j - i)) * (pos[j] - pos[j-]), f[i][j-][] + (n - (j - i)) * (pos[j] - pos[i])));
}
}
printf("%d\n", min(f[][n][], f[][n][]));
return ;
}
[BZOJ1694/1742/3074]The Cow Run 三倍经验的更多相关文章
- 洛谷P3080 [USACO13MAR]牛跑The Cow Run
P3080 [USACO13MAR]牛跑The Cow Run 题目描述 Farmer John has forgotten to repair a hole in the fence on his ...
- 「USACO13MAR」「LuoguP3080」 牛跑The Cow Run (区间dp
题目描述 Farmer John has forgotten to repair a hole in the fence on his farm, and his N cows (1 <= N ...
- bzoj1742[Usaco2005 nov]Grazing on the Run 边跑边吃草*&&bzoj3074[Usaco2013 Mar]The Cow Run*
bzoj1742[Usaco2005 nov]Grazing on the Run 边跑边吃草 bzoj3074[Usaco2013 Mar]The Cow Run 题意: 数轴上有n棵草,牛初始在L ...
- bzoj2581 [USACO 2012 Jan Gold] Cow Run【And-Or Tree】
传送门1:http://www.usaco.org/index.php?page=viewproblem2&cpid=110 传送门2:http://www.lydsy.com/JudgeOn ...
- BZOJ-USACO被虐记
bzoj上的usaco题目还是很好的(我被虐的很惨. 有必要总结整理一下. 1592: [Usaco2008 Feb]Making the Grade 路面修整 一开始没有想到离散化.然后离散化之后就 ...
- bzoj AC倒序
Search GO 说明:输入题号直接进入相应题目,如需搜索含数字的题目,请在关键词前加单引号 Problem ID Title Source AC Submit Y 1000 A+B Problem ...
- Usaco2012-2013 金组 题解 (暂缺Hill walk以及Figue eight)
https://files.cnblogs.com/files/Winniechen/usaco2012-2013.pdf 做的不是很好,还请见谅! 如果有什么疑问,可以QQ上找我. QQ号:1967 ...
- BZOJ 1742: [Usaco2005 nov]Grazing on the Run 边跑边吃草( dp )
dp... dp( l , r , k ) , 表示 吃了[ l , r ] 的草 , k = 1 表示最后在 r 处 , k = 0 表示最后在 l 处 . ------------------- ...
- bzoj 1742: [Usaco2005 nov]Grazing on the Run 边跑边吃草【区间dp】
挺好的区间dp,状态设计很好玩 一开始按套路设f[i][j],g[i][j]为吃完(i,j)区间站在i/j的最小腐败值,后来发现这样并不能保证最优 实际上是设f[i][j],g[i][j]为从i开始吃 ...
随机推荐
- 12 (OC)* AFNetworking
AFNetworking主要是对NSURLSession和NSURLConnection(iOS9.0废弃)的封装,其中主要有以下类:1). AFHTTPRequestOperationManager ...
- C++基础之IO类
下面是IO类的继承关系: ifstream和istringstream都继承自istream.因此,我们可以在传递istream对象的地方传递ifstream和istringstream. 例如:对i ...
- Beescms_v4.0 sql注入漏洞分析
Beescms_v4.0 sql注入漏洞分析 一.漏洞描述 Beescms v4.0由于后台登录验证码设计缺陷以及代码防护缺陷导致存在bypass全局防护的SQL注入. 二.漏洞环境搭建 1.官方下载 ...
- Python+OpenCV竖版古籍文字分割
在做图片文字分割的时候,常用的方法有两种.一种是投影法,适用于排版工整,字间距行间距比较宽裕的图像:还有一种是用OpenCV的轮廓检测,适用于文字不规则排列的图像. 1. 思路 一开始想偷个懒,直接用 ...
- mybatis 插件的原理-责任链和动态代理的体现
目录 1 拦截哪些方法 2 如何代理 3 代理对象 4 责任链设计模式 @ 如果没有自定义过拦截器, 可以看我前面的文章.如果不知道 JDK 动态代理怎么使用的, 可以看我这文章. 责任链设计模式理解 ...
- 环境搭建-CentOS集群搭建
环境搭建-CentOS集群搭建 写在前面 最近有许多小伙伴问我,大数据的hadoop分布式集群该如何去搭建.所以,想着,就写一篇博客,帮助到更多刚入门大数据的人.本博客会一步一步带你实现一个Hadoo ...
- 对象实例Vue
var vm = new Vue({ el:'#app', data:{}, //数据 methods:{}, //方法调用 filters:{}, //私有过滤器 directives:{}, // ...
- C/C++中变量的作用域和存储类型简介
写在开头 对于很多C/C++的初学者来说,很容易理不清变量的作用域和存储类型这一块的一些概念,也容易将其中的一些概念搞混淆.作为一个C/C++的初学者,笔者希望在这里能够尝试着去理一理这些较为繁杂的概 ...
- idea在debug模式下的启动特别慢?
程序执行到这里时,一直卡着不动? 原因可能是在方法上打了断点导致的: 将方法上的断点去掉,点击[Done]即可.
- String 用法 简单API
明天天梯赛选拔,怕不是STl忘到姥姥家去了,赶紧复习一下 构造str string s = "fuckyouRMA"; string s1(s, 2); de(s1); strin ...