[USACO13NOV] Pogo-Cow
https://www.luogu.org/problem/show?pid=3089
题目描述
In an ill-conceived attempt to enhance the mobility of his prize cow Bessie, Farmer John has attached a pogo stick to each of Bessie's legs. Bessie can now hop around quickly throughout the farm, but she has not yet learned how to slow down.
To help train Bessie to hop with greater control, Farmer John sets up a practice course for her along a straight one-dimensional path across his farm. At various distinct positions on the path, he places N targets on which Bessie should try to land (1 <= N <= 1000). Target i is located at position x(i), and is worth p(i) points if Bessie lands on it. Bessie starts at the location of any target of her choosing and is allowed to move in only one direction, hopping from target to target. Each hop must cover at least as much distance as the previous hop, and must land on a target.
Bessie receives credit for every target she touches (including the initial target on which she starts). Please compute the maximum number of points she can obtain.
FJ给奶牛贝西的脚安装上了弹簧,使它可以在农场里快速地跳跃,但是它还没有学会如何降低速度。
FJ觉得让贝西在一条直线的一维线路上进行练习,他在不同的目标点放置了N (1 <= N <= 1000)个目标点,目标点i在目标点x(i),该点得分为p(i)。贝西开始时可以选择站在一个目标点上,只允许朝一个方向跳跃,从一目标点跳到另外一个目标点,每次跳跃的距离至少和上一次跳跃的距离相等,并且必须跳到一个目标点。
每跳到一个目标点,贝西可以拿到该点的得分,请计算他的最大可能得分。
输入输出格式
输入格式:
Line 1: The integer N.
- Lines 2..1+N: Line i+1 contains x(i) and p(i), each an integer in the range 0..1,000,000.
输出格式:
- Line 1: The maximum number of points Bessie can receive.
输入输出样例
6
5 6
1 1
10 5
7 6
4 8
8 10
25
说明
There are 6 targets. The first is at position x=5 and is worth 6 points, and so on.
Bessie hops from position x=4 (8 points) to position x=5 (6 points) to position x=7 (6 points) to position x=10 (5 points).
82分做法:
dp[i][j] 表示 i是由j转移过来的最大得分
枚举k转移
#include<cstdio>
#include<cstring>
#include<algorithm>
#define N 1001
using namespace std;
int n,ans,dp1[N][N],dp2[N][N];
struct node
{
int x,v;
}e[N];
bool cmp(node p,node q)
{
return p.x<q.x;
}
int main()
{
scanf("%d",&n);
for(int i=;i<=n;i++) scanf("%d%d",&e[i].x,&e[i].v);
sort(e+,e+n+,cmp);
for(int i=;i<=n;i++)
for(int j=;j<i;j++)
{
for(int k=;k<j;k++)
{
if(e[i].x-e[j].x>=e[j].x-e[k].x) dp1[i][j]=max(dp1[i][j],dp1[j][k]);
if(e[i].x-e[j].x<=e[j].x-e[k].x) dp2[i][j]=max(dp2[i][j],dp2[j][k]);
}
dp1[i][j]=max(dp1[i][j],dp1[j][]);
dp1[i][j]+=e[i].v;
dp2[i][j]=max(dp2[i][j],dp2[j][]);
dp2[i][j]+=e[i].v;
ans=max(ans,max(dp1[i][j],dp2[i][j]));
}
printf("%d",ans);
}
55分做法:
记忆化搜索
#include<cstdio>
#include<cstring>
#include<algorithm>
#define N 1001
using namespace std;
int n,ans,dp1[N][N],dp2[N][N];
struct node
{
int x,v;
bool operator < (node p)const
{
return x<p.x;
}
}e[N];
int dfs1(int s,int t,int dis)
{
if(dp1[s][t]) return dp1[s][t];
for(int i=t+;i<=n;i++)
if(e[i].x-e[t].x>=dis) dp1[s][t]=max(dp1[s][t],dfs1(t,i,e[i].x-e[t].x)+e[i].v);
return dp1[s][t];
}
int dfs2(int s,int t,int dis)
{
if(dp2[s][t]) return dp2[s][t];
for(int i=t+;i<=n;i++)
if(e[i].x-e[t].x<=dis) dp2[s][t]=max(dp2[s][t],dfs2(t,i,e[i].x-e[t].x)+e[i].v);
return dp2[s][t];
}
int main()
{
scanf("%d",&n);
for(int i=;i<=n;i++) scanf("%d%d",&e[i].x,&e[i].v);
sort(e+,e+n+);
for(int i=;i<n;i++)
for(int j=i+;j<=n;j++)
{ dp1[i][j]=dfs1(i,j,e[j].x-e[i].x)+e[i].v+e[j].v;
dp2[i][j]=dfs2(i,j,e[j].x-e[i].x)+e[i].v+e[j].v;
ans=max(ans,max(dp1[i][j],dp2[i][j]));
}
printf("%d\n",ans);
}
36分做法:
普通搜索
#include<cstdio>
#include<algorithm>
#define N 1001
using namespace std;
int n,ans;
struct node
{
int x,v;
bool operator < (node p)const
{
return x<p.x;
}
}e[N];
int dfs1(int s,int t,int dis,int sum)
{
ans=max(ans,sum);
for(int i=t+;i<=n;i++)
if(e[i].x-e[t].x>=dis) dfs1(t,i,e[i].x-e[t].x,sum+e[i].v);
}
int dfs2(int s,int t,int dis,int sum)
{
ans=max(ans,sum);
for(int i=t+;i<=n;i++)
if(e[i].x-e[t].x<=dis) dfs2(t,i,e[i].x-e[t].x,sum+e[i].v);
}
int main()
{
scanf("%d",&n);
for(int i=;i<=n;i++) scanf("%d%d",&e[i].x,&e[i].v);
sort(e+,e+n+);
for(int i=;i<n;i++)
for(int j=i+;j<=n;j++)
{
dfs1(i,j,e[j].x-e[i].x,e[i].v+e[j].v);
dfs2(i,j,e[j].x-e[i].x,e[i].v+e[j].v);
}
printf("%d\n",ans);
}
[USACO13NOV] Pogo-Cow的更多相关文章
- [luogu] P3089 [USACO13NOV]POGO的牛Pogo-Cow
P3089 [USACO13NOV]POGO的牛Pogo-Cow 题目描述 In an ill-conceived attempt to enhance the mobility of his pri ...
- P3089 [USACO13NOV]POGO的牛Pogo-Cow
P3089 [USACO13NOV]POGO的牛Pogo-Cow FJ给奶牛贝西的脚安装上了弹簧,使它可以在农场里快速地跳跃,但是它还没有学会如何降低速度. FJ觉得让贝西在一条直线的一维线路上进行练 ...
- DP【洛谷P3089】 [USACO13NOV]POGO的牛Pogo-Cow
[洛谷P3089] [USACO13NOV]POGO的牛Pogo-Cow FJ给奶牛贝西的脚安装上了弹簧,使它可以在农场里快速地跳跃,但是它还没有学会如何降低速度. FJ觉得让贝西在一条直线的一维线路 ...
- 洛谷 3089 [USACO13NOV]POGO的牛Pogo-Cow
单调队列优化dp; 对于每个点开个单调队列,按转移到它的点到它的距离从大到小,得分也从大到小排列. 每次枚举当前点前面的所有点,对于每个点的队列中二分一个距离小于等于它到当前点的答案值,放到当前点的队 ...
- dp专题练习
顺便开另外一篇放一些学过的各种dp dp总结:https://www.cnblogs.com/henry-1202/p/9194066.html 开坑先放15道题,后面慢慢补 目标50道题啦~~,目前 ...
- 洛谷 P3088 [USACO13NOV]挤奶牛Crowded Cows 题解
P3088 [USACO13NOV]挤奶牛Crowded Cows 题目描述 Farmer John's N cows (1 <= N <= 50,000) are grazing alo ...
- POJ 3278 Catch That Cow(bfs)
传送门 Catch That Cow Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 80273 Accepted: 25 ...
- 【BZOJ1623】 [Usaco2008 Open]Cow Cars 奶牛飞车 贪心
SB贪心,一开始还想着用二分,看了眼黄学长的blog,发现自己SB了... 最小道路=已选取的奶牛/道路总数. #include <iostream> #include <cstdi ...
- HDU Cow Sorting (树状数组)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2838 Cow Sorting Problem Description Sherlock's N (1 ...
随机推荐
- ViewPager的简单使用说明
前提:工程中使用ViewPager,需要导入google提供的jar包(android-support-v4.jar). 要学习ViewPager的使用,建议直接看官方文档 Creating Swip ...
- Saruman's Army(贪心)
Saruman the White must lead his army along a straight path from Isengard to Helm’s Deep. To keep tra ...
- 11.22Daily Scrum(2)
人员 任务分配完成情况 明天任务分配 王皓南 实现网页上视频浏览的功能.研究相关的代码和功能.984 数据库测试 申开亮 实现网页上视频浏览的功能.研究相关的代码和功能.985 实现视频浏览的功能 王 ...
- c# 计算两个时间的时间差
//计算2个日期之间的天数差 DateTime dt1 = Convert.ToDateTime("2007-8-1"); DateTime dt2 = Convert.ToDat ...
- Linux内核策略介绍学习笔记
主要内容 硬件 策略 CPU 进程调度.系统调用.中断 内存 内存管理 外存 文件IO 网络 协议栈 其他 时间管理 进程调度 内核的运行时间 系统启动.中断发生.系统调用以及内核线程. 进程和线程的 ...
- 《学习OpenCV》课后习题解答5
题目:(P104) 为一个图像创建多个图像头.读取一个大小至少为100*100的图像.另创建两个图像头并设置它们的origion,depth,nChannels和widthStep属性同之前读取的图像 ...
- Vim新手节省时间的10多个小技巧
Vim新手节省时间的10多个小技巧 Vim 是很多开发者的首选编辑器,通过设置正确的命令和快捷方式,它可以帮你更快的完成工作.这篇文章我们为 Vim 新手提供一些快捷键等方面的小技巧,帮你提升工作效率 ...
- 在线api查询网站
1.包含各种常用的语言 http://tool.oschina.net/apidocs
- Sass的命令编译
[Sass]命令编译 命令编译是指使用你电脑中的命令终端,通过输入 Sass 指令来编译 Sass.这种编译方式是最直接也是最简单的一种方式.因为只需要在你的命令终端输入: 单文件编译: sass & ...
- 扩展SplitContainer控件
效果图: 自定义控件实现代码: using System; using System.ComponentModel; using System.Drawing; using System.Window ...