[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开始吃 ...
随机推荐
- charles 启用/禁用断点
本文参考:charles 启用/禁用断点 1.3. enable/disable breakpoints 和 2.3 breakpoints settings 断点设置是常用的了,没啥好说的了,可以设 ...
- DirectX12 3D 游戏开发与实战第一章内容
DirectX12 3D 第一章内容 学习目标 1.学习向量在几何学和数学中的表示方法 2.了解向量的运算定义以及它在几何学中的应用 3.熟悉DirectXMath库中与向量有关的类和方法 1.1 向 ...
- 会用python把linux命令写一遍的人,进大厂有多容易?
看过这篇<2000字谏言,给那些想学Python的人,建议收藏后细看!>的读者应该都对一个命令有点印象吧?没错,就是 linux 中经常会用到的 ls 命令. 文章中我就提到如何提升自己的 ...
- Java 集合转换(数组、List、Set、Map相互转换)
package com.example.test; import java.util.ArrayList; import java.util.Arrays; import java.util.Hash ...
- RxSwift 入门
ReactiveX 是一个库,用于通过使用可观察序列来编写异步的.基于事件的程序. 它扩展了观察者模式以支持数据.事件序列,并添加了允许你以声明方式组合序列的操作符,同时抽象对低层线程.同步.线程安全 ...
- 使用Spreadsheet导出表格时,设置样式
$spreadsheet = new Spreadsheet();// 初始化 $spreadsheet->createSheet();// 添加一个sheet ...
- 第九周java动手动脑
1.使用Files. walkFileTree()找出指定文件夹下所有扩展名为.txt和.java的文件. import java.io.IOException; import java.nio.fi ...
- WEB开发中常见的漏洞
一.SQL注入漏洞 SQL注入攻击(SQL Injection),简称注入攻击.SQL注入,被广泛用于非法获取网站控制权,是发生在应用程序的数据库层上的安全漏洞.在设计程序,忽略了对输入字符串中夹带的 ...
- Mysql高手系列 - 第21篇:什么是索引?
Mysql系列的目标是:通过这个系列从入门到全面掌握一个高级开发所需要的全部技能. 这是Mysql系列第21篇. 本文开始连续3篇详解mysql索引: 第1篇来说说什么是索引? 第2篇详解Mysql中 ...
- SpringBootSecurity学习(17)前后端分离版之 OAuth2.0 数据库(JDBC)存储客户端
自动批准授权码 前面我们授权的流程中,第一步获取授权码的时候,都会经历一个授权是否同意页面: 这个流程就像第三方登录成功后,提问是否允许获取昵称和头像信息的页面一样,这个过程其实是可以自动同意的,需要 ...