Description

John养了一只叫Joseph的奶牛。一次她去放牛,来到一个非常长的一片地,上面有N块地方长了茂盛的草。我们可
以认为草地是一个数轴上的一些点。Joseph看到这些草非常兴奋,它想把它们全部吃光。于是它开始左右行走,吃
草。John和Joseph开始的时候站在p位置。Joseph的移动速度是一个单位时间一个单位距离。不幸的是,草如果长
时间不吃,就会腐败。我们定义一堆草的腐败值是从Joseph开始吃草到吃到这堆草的总时间。Joseph可不想吃太腐
败的草,它请John帮它安排一个路线,使得它吃完所有的草后,总腐败值最小。John的数学很烂,她不知道该怎样
做,你能帮她么?

Input

* Line 1 : Two space-separated integers: N and L. N<=1000
* Lines 2..N+1: Each line contains a single integer giving the position P of a clump (1 <= P <= 1,000,000).

Output

* Line 1: A single integer: the minimum total staleness Bessie can achieve while eating all the clumps.

Sample Input

4 10
1
9
11
19
INPUT DETAILS:
Four clumps: at 1, 9, 11, and 19. Bessie starts at location 10.

Sample Output

44
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
 
 

 
 
感觉翻译的不太好..但也能看2333.
发现了三倍经验,但都是权限题2333.
对于我这种非权限汪很不友好...
然而凭借三道题成功将yousiki学长刷题量冲到日榜第45...
虽然不知道干了些什么昨天我日榜第5.玄学我都不知道昨天做了些什么2333;
 
吐槽结束。
水水的区间dp秒出思路,,,
设f[i][j][0/1]表示处理完了i~j区间,现在在左端点/右端点的最小损失。
于是f[i][j][0] 可以从 f[i+1][j][0/1]转移过来,f[i][j][1] 可以从 f[i][j-1][0/1]转移过来。。
我也是第一次见区间dp没有枚举k...见识太少了233
 

 
贴那篇题解呢。。。
对了注意bzoj3074和另外两个不太一样,从输入可以看出来。
这里贴bzoj1694的。
// 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 三倍经验的更多相关文章

  1. 洛谷P3080 [USACO13MAR]牛跑The Cow Run

    P3080 [USACO13MAR]牛跑The Cow Run 题目描述 Farmer John has forgotten to repair a hole in the fence on his ...

  2. 「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 ...

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

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

  5. BZOJ-USACO被虐记

    bzoj上的usaco题目还是很好的(我被虐的很惨. 有必要总结整理一下. 1592: [Usaco2008 Feb]Making the Grade 路面修整 一开始没有想到离散化.然后离散化之后就 ...

  6. bzoj AC倒序

    Search GO 说明:输入题号直接进入相应题目,如需搜索含数字的题目,请在关键词前加单引号 Problem ID Title Source AC Submit Y 1000 A+B Problem ...

  7. Usaco2012-2013 金组 题解 (暂缺Hill walk以及Figue eight)

    https://files.cnblogs.com/files/Winniechen/usaco2012-2013.pdf 做的不是很好,还请见谅! 如果有什么疑问,可以QQ上找我. QQ号:1967 ...

  8. BZOJ 1742: [Usaco2005 nov]Grazing on the Run 边跑边吃草( dp )

    dp... dp( l , r , k )  , 表示 吃了[ l , r ] 的草 , k = 1 表示最后在 r 处 , k = 0 表示最后在 l 处 . ------------------- ...

  9. 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开始吃 ...

随机推荐

  1. web性能优化实践

    一.SQL查询优化 1.循环中有多次查询sql,改为在循环外一次查询后再处理 2.循环多次插入,改为组装好数据后批量插入 3.梳理业务逻辑能一次查完的,绝不分多次查 4.索引用起来 5.分页查询 二. ...

  2. IBM DB2 SQL error code list

    SQL return codes that are preceded by a minus sign (-) indicate that the SQL statement execution was ...

  3. PTA A1013

    第七天 A1013 Battle Over Cities (25 分) 题目内容 It is vitally important to have all the cities connected by ...

  4. .Net Core WebApi(二)在Windows服务器上部署

    上一篇学习到了如何简单的创建.Net Core Api和Swagger使用,既然写了接口,那么就需要部署到服务器上才能够正式使用.服务器主要用到了两种系统,Windows和Linux,.Net和Win ...

  5. MySQL-Access denied for user 'username'@'localhost' (using password: YES) 解决

    使用navicat新建MySQL用户保存时提示 Access denied for user 'username'@'localhost' (using password: YES): 解决方法: 请 ...

  6. linux系统下使用xampp 丢失mysql root密码 只能远程访问,本地无法连接数据库

    如果在ubuntu 下面 使用xampp这个集成开发环境,却忘记mysql密码. 当出现只能远程访问的,本地无法访问,通常是host改成% 远程访问,本地访问到一个是空壳.这是权限的问题 需要修hos ...

  7. C语言复习————基本数据类型、运算符和表达式

    数据类型/运算符/表达式 主要分两部分介绍,第一部分介绍常用的数据类型,例如:常量和变量/整型/实型/字符型:第二部分介绍算数运算符和算数表达式以及赋值运算符和逗号运算符. 一. 常用的数据类型 1. ...

  8. [Python] Python 学习记录(1)

    1.概论 弱类型 一个变量能被赋值时能与原类型不同 x = 1 x = "1"  #不加分号,给x赋值为int后再次赋值为string是可行的 与或非 and or not /  ...

  9. JVM(一)内存分配

    方法区: ①存储被虚拟机加载的类信息.常量.静态变量.即时编译器编译后的代码数据 ②又称为永久代,仅对于Hotspot来讲,JRockit和IBM J9里面没有永久代的概念,1.8以后是元空间,直接使 ...

  10. 分库分表(3) ---SpringBoot + ShardingSphere 实现读写分离

    分库分表(3)---ShardingSphere实现读写分离 有关ShardingSphere概念前面写了两篇博客: 1.分库分表(1) --- 理论 2. 分库分表(2) --- ShardingS ...