Codeforces 358 D. Dima and Hares
dp[i][0]表示i号兔子先于i-1号兔子喂食,dp[i][1]反过来.
倒着DP
2 seconds
256 megabytes
standard input
standard output
Dima liked the present he got from Inna very much. He liked the present he got from Seryozha even more.
Dima felt so grateful to Inna about the present that he decided to buy her n hares. Inna was very happy. She lined up the hares in a row, numbered them from
1 to n from left to right and started feeding them with carrots. Inna was determined to feed each hare exactly once. But in what order should she feed them?
Inna noticed that each hare radiates joy when she feeds it. And the joy of the specific hare depends on whether Inna fed its adjacent hares before feeding it. Inna knows how much joy a hare radiates if it eats when either both of his adjacent hares are hungry,
or one of the adjacent hares is full (that is, has been fed), or both of the adjacent hares are full. Please note that hares number 1 and n don't have a
left and a right-adjacent hare correspondingly, so they can never have two full adjacent hares.
Help Inna maximize the total joy the hares radiate. :)
The first line of the input contains integer n (1 ≤ n ≤ 3000) —
the number of hares. Then three lines follow, each line has n integers. The first line contains integers a1 a2 ... an.
The second line contains b1, b2, ..., bn.
The third line contains c1, c2, ..., cn.
The following limits are fulfilled: 0 ≤ ai, bi, ci ≤ 105.
Number ai in
the first line shows the joy that hare number i gets if his adjacent hares are both hungry. Number bi in
the second line shows the joy that hare number i radiates if he has exactly one full adjacent hare. Number сi in
the third line shows the joy that hare number iradiates if both his adjacent hares are full.
In a single line, print the maximum possible total joy of the hares Inna can get by feeding them.
4
1 2 3 4
4 3 2 1
0 1 1 0
13
7
8 5 7 6 1 8 9
2 7 9 5 4 3 1
2 3 3 4 1 1 3
44
3
1 1 1
1 2 1
1 1 1
4
/**
* Created by ckboss on 14-10-6.
*/
import java.util.*; public class DimaandHares {
public static void main(String[] args){
Scanner in = new Scanner(System.in);
int n=in.nextInt();
int[] A=new int[n+10],B=new int[n+10],C=new int[n+10];
int[][] dp = new int[n+10][2];
for(int i=1;i<=n;i++) A[i]=in.nextInt();
for(int i=1;i<=n;i++) B[i]=in.nextInt();
for(int i=1;i<=n;i++) C[i]=in.nextInt();
dp[n][0]=A[n]; dp[n][1]=B[n];
for(int i=n-1;i>0;i--)
{
dp[i][0]=Math.max(dp[i][0],dp[i+1][0]+B[i]);
dp[i][0]=Math.max(dp[i][0],dp[i+1][1]+A[i]);
dp[i][1]=Math.max(dp[i][1],dp[i+1][1]+B[i]);
dp[i][1]=Math.max(dp[i][1],dp[i+1][0]+C[i]);
}
System.out.println(dp[1][0]);
}
}
Codeforces 358 D. Dima and Hares的更多相关文章
- CF358D Dima and Hares
CF358D Dima and Hares 洛谷评测传送门 题目描述 Dima liked the present he got from Inna very much. He liked the p ...
- Codeforces Round #208 (Div. 2) 358D Dima and Hares
题目链接:http://codeforces.com/problemset/problem/358/D 开始题意理解错,整个就跪了= = 题目大意:从1到n的位置取数,取数的得到值与周围的数有没有取过 ...
- Codeforces 358D Dima and Hares
http://codeforces.com/contest/358/problem/D 题意:给出n个数,每个数取走的贡献与相邻的数有关,如果取这个数的时候,左右的数都还没被取,那么权值为a,如果左右 ...
- Codeforces 358D Dima and Hares:dp【只考虑相邻元素】
题目链接:http://codeforces.com/problemset/problem/358/D 题意: 有n个物品A[i]摆成一排,你要按照某一个顺序将它们全部取走. 其中,取走A[i]的收益 ...
- cf D. Dima and Hares
http://codeforces.com/contest/358/problem/D 题意:ai代表相邻的两个野兔都没有吃食物情况下的快乐系数,bi代表的是在相邻的两个野兔中有一个吃到食物的快乐系数 ...
- codeforces 460B Little Dima and Equation 解题报告
题目链接:http://codeforces.com/problemset/problem/460/B 题目意思:给出a, b, c三个数,要你找出所有在 1 ≤ x ≤ 1e9 范围内满足 x = ...
- [CodeForce]358D Dima and Hares
有N<3000只宠物要喂,每次只能喂一只,每喂一只宠物,宠物的满足度取决于: 1 紧靠的两个邻居都没喂,a[i] 2 邻居中有一个喂过了,b[i] 3 两个邻居都喂过了,c[i] 把所有宠物喂一 ...
- codeforces358D Dima and Hares【dp】
从本质入手,这个东西影响取值的就是相邻两个哪个先取 设f[i][0/1]为前i个(i-1,i)中先取i/i-1的值(这里不算上i的贡献 转移就显然了,注意要先复制-inf #include<io ...
- 【Codeforces 584D】Dima and Lisa
[链接] 我是链接,点我呀:) [题意] 让你把一个奇数n分成最多个质数的和 [题解] 10的9次方以内,任意两个质数之间的差距最大为300 因此可以这样,我们先从i=n-2开始一直递减直到i变成最大 ...
随机推荐
- BNU Box of Bricks
http://www.bnuoj.com/bnuoj/problem_show.php?pid=1596 这个题一开始以为要求最少移动次数,把我吓到了,原来只要求最少移动几个方块就行了..这一下就变简 ...
- java.lang.NoClassDefFoundError: ognl/PropertyAccessor解决的方法
本来不想为这个专门写一篇文章的,可是发现这么简单的一个问题居然没有人好好回答过.从方便搜索的角度考虑,特意取了这么一个题目. 事实上解决方法就是将ognl的jar包增加就可以. 比方我用的是ognl3 ...
- 动态链接库dll的 静态加载 与 动态加载
dll 两种链接方式 : 动态链接和静态链接(链接亦称加载) 动态链接是指在生成可执行文件时不将所有程序用到的函数链接到一个文件,因为有许多函数在操作系统带的dll文件中,当程序运行时直接从操作系统 ...
- PHP脚本监控程序
#!/bin/sh # Find ip IP=`/sbin/ifconfig eth1 | grep 'inet addr' | awk '{ print substr($2, index($2, & ...
- mysql导入sql文件过大或连接超时的解决的方法
前段时间出差在现场开发的时候,导入数据库老是出问题.最后发现了一个奇妙sql语句交给实施,仅仅要导入出错就把例如以下语句运行就能够了.至今屡试不爽. set global max_allowed_pa ...
- Java基础08 继承
作者:Vamei 出处:http://www.cnblogs.com/vamei 欢迎转载,也请保留这段声明.谢谢! 继承(inheritance)是面向对象的重要概念.继承是除组合(composit ...
- 不用SWIG,Go使用C++代码的方式
将C++代码用C作一次封装,就可以让Go调用了. 这是一个C++头文件: ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 #ifndef CGO_CPPGO_C ...
- 分布式消息系统jafka快速起步(转)
Jafka 是一个开源的/性能良好的分布式消息系统.在上一篇文章中有所简单介绍.下面是一篇简单的入门文档.更多详细的文档参考wiki. Step 1: 下载最新的安装包 完整的安装指南在这里.最新的发 ...
- Python 脚本帮你找出微信上删除了你的“好友“
- C#的静态构造函数
“静态构造函数”典型应用于第一次使用类时的初始化工作,注意“第一次”,意思是它只执行一次. 有同学说了,类的初始化不是有构造函数嘛?我们回答:构造函数是每个实例被声明时都会执行的,它属于每一个实例,而 ...