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的。
  1. // By BriMon
  2. #include <iostream>
  3. #include <cstring>
  4. #include <cstdio>
  5. #include <cmath>
  6. #include <algorithm>
  7. using namespace std;
  8. inline int read(){
  9. int res=;char ch=getchar();
  10. while(!isdigit(ch)) ch=getchar();
  11. while(isdigit(ch)){res=(res<<)+(res<<)+(ch^);ch=getchar();}
  12. return res;
  13. }
  14.  
  15. int n, x;
  16. int f[][][], pos[];
  17.  
  18. int main()
  19. {
  20. n = read(), x = read();
  21. for (int i = ; i <= n ; i ++)
  22. pos[i] = read();
  23. sort(pos + , pos + + n);
  24. memset(f, 0x3f, sizeof f);
  25. for (int i = ; i <= n ; i ++) f[i][i][] = f[i][i][] = abs(x - pos[i]) * n;
  26. for (int len = ; len <= n ; len ++)
  27. {
  28. for (int i = ; i <= n ; i ++)
  29. {
  30. int j = i + len - ;
  31. if (j > n) break;
  32. 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])));
  33. 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])));
  34. }
  35. }
  36. printf("%d\n", min(f[][n][], f[][n][]));
  37. return ;
  38. }

[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. b146: NOIP2004 1.不高兴的津津

    题目: 津津上初中了.妈妈认为津津应该更加用功学习,所以津津除了上学之外,还要参加妈妈为她报名的各科复习班.另外每周妈妈还会送她去学习朗诵.舞蹈和钢琴.但是津津如果一天上课超过八个小时就会不高兴,而且 ...

  2. 初识数据库(MySql)

    一.简介 1.MySql是关系型数据库. 2.是一种开放源码软件, 3.是一种关联数据库管理系统. 4.服务器工作于客户端/服务端模式之下,或者是嵌入系统中. 数据库管理软件分类: 分两大类: 关系型 ...

  3. [Scikit-learn] 4.3 Preprocessing data

    数据分析的重难点,就这么来了,欢迎欢迎,热烈欢迎. 4. Dataset transformations 4.3. Preprocessing data 4.3.1. Standardization, ...

  4. 一个简单的jquery ajax表单提交 带数据校验 layer弹框提示

    <input type="hidden" id="url" value="index.php"/> <form id=&q ...

  5. 关于CDH集群spark的三种安装方式简述

    一.spark的命令行模式 1.第一种进入方式:执行 pyspark进入,执行exit()退出 注意报错信息:java.lang.IllegalArgumentException: Required ...

  6. pycharm远程代码调试

    1.pycharm连接linux服务器并上传功能 # Tools-->Deployment-->Configuration # 点击+号,选择SFTP类型,name填项目名字-->填 ...

  7. mysql数据库安全性配置——日志记录

    一:开启数据库日志记录 (1)在查看数据库是否开启日志记录,默认是OFF,即关闭状态.(可在数据库中执行该查询语句,也可在服务器端执行) show variables like 'log_bin'; ...

  8. CentOS 安装lsof命令

    1.在控制台上输入:# yum install lsof,安装过程中按y进行确认 2.使用lsof -i :port 可以产看端口的进程信息

  9. 关于.NET HttpClient方式获取微信小程序码(二维码)

    随着微信小程序的火热应用,市面上有关小程序开发的需求也多了起来.近来分析了一项生成有关生成微信小程序码的需求——要求扫码跳转到小程序指定页面(带参数):看了下小程序官方文档文档,结合网上的例子,未看到 ...

  10. Python Excel操作——xlrd、xlwd

    读取 1.导入模块 import xlrd 2.打开Excel文件读取数据 data = xlrd.open_workbook('excel.xls') 3.获取一个工作表 1 table = dat ...