dp[i][0]表示i号兔子先于i-1号兔子喂食,dp[i][1]反过来.

倒着DP

D. Dima and Hares
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

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. :)

Input

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

Output

In a single line, print the maximum possible total joy of the hares Inna can get by feeding them.

Sample test(s)
input
4
1 2 3 4
4 3 2 1
0 1 1 0
output
13
input
7
8 5 7 6 1 8 9
2 7 9 5 4 3 1
2 3 3 4 1 1 3
output
44
input
3
1 1 1
1 2 1
1 1 1
output
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的更多相关文章

  1. CF358D Dima and Hares

    CF358D Dima and Hares 洛谷评测传送门 题目描述 Dima liked the present he got from Inna very much. He liked the p ...

  2. Codeforces Round #208 (Div. 2) 358D Dima and Hares

    题目链接:http://codeforces.com/problemset/problem/358/D 开始题意理解错,整个就跪了= = 题目大意:从1到n的位置取数,取数的得到值与周围的数有没有取过 ...

  3. Codeforces 358D Dima and Hares

    http://codeforces.com/contest/358/problem/D 题意:给出n个数,每个数取走的贡献与相邻的数有关,如果取这个数的时候,左右的数都还没被取,那么权值为a,如果左右 ...

  4. Codeforces 358D Dima and Hares:dp【只考虑相邻元素】

    题目链接:http://codeforces.com/problemset/problem/358/D 题意: 有n个物品A[i]摆成一排,你要按照某一个顺序将它们全部取走. 其中,取走A[i]的收益 ...

  5. cf D. Dima and Hares

    http://codeforces.com/contest/358/problem/D 题意:ai代表相邻的两个野兔都没有吃食物情况下的快乐系数,bi代表的是在相邻的两个野兔中有一个吃到食物的快乐系数 ...

  6. codeforces 460B Little Dima and Equation 解题报告

    题目链接:http://codeforces.com/problemset/problem/460/B 题目意思:给出a, b, c三个数,要你找出所有在 1 ≤ x ≤ 1e9 范围内满足 x =  ...

  7. [CodeForce]358D Dima and Hares

    有N<3000只宠物要喂,每次只能喂一只,每喂一只宠物,宠物的满足度取决于: 1 紧靠的两个邻居都没喂,a[i] 2 邻居中有一个喂过了,b[i] 3 两个邻居都喂过了,c[i] 把所有宠物喂一 ...

  8. codeforces358D Dima and Hares【dp】

    从本质入手,这个东西影响取值的就是相邻两个哪个先取 设f[i][0/1]为前i个(i-1,i)中先取i/i-1的值(这里不算上i的贡献 转移就显然了,注意要先复制-inf #include<io ...

  9. 【Codeforces 584D】Dima and Lisa

    [链接] 我是链接,点我呀:) [题意] 让你把一个奇数n分成最多个质数的和 [题解] 10的9次方以内,任意两个质数之间的差距最大为300 因此可以这样,我们先从i=n-2开始一直递减直到i变成最大 ...

随机推荐

  1. JAVA中MESSAGEBOX,静态类直接引用

    原文:JAVA中MESSAGEBOX,静态类直接引用 package cisdi.mes.wrm.mcode.serviceImpl; import javax.persistence.Entity; ...

  2. 基于visual Studio2013解决C语言竞赛题之0710排序函数

     题目

  3. Shell脚本笔记

      如何查询文件里的某个字符串? grep “字符串” 文件 例:grep "abc" tmp.txt   如何将查询出来的内容赋给变量? str=$(grep "abc ...

  4. 它们偷偷干了啥?教你监督APP的运行

    由于Android系统的开放性,很多APP都会在后台运行各种我们不知道的权限,不仅泄露我们隐私,也给系统本身带来极大安全隐患.而且现在很普遍的是,在安装APP时它总会索取特别多的权限,又是拍照又是地理 ...

  5. 配置rhel 6.4(64位)安装使用syslog-ng 3.5

    我基本的博客地址是:www.cppblog.com/zdhsoft 相应的CentOS 6.x也就可能使用. 下载地址: 第一步:安装 wget http://www.balabit.com/down ...

  6. Atitit.dwr3 不能显示错误具体信息的解决方式,控件显示错误具体信息的解决方式 java .net php

    Atitit.dwr3 不能显示错误具体信息的解决方式,控件显示错误具体信息的解决方式 java .net php 1. Keyword/subtitle 1 2. 使用dwr3的异常convert处 ...

  7. Silverlight技术调查(3)——国际化

    原文 Silverlight技术调查(3)——国际化 网上有很多关于Silverlight国际化的说明,包括MSDN的示例,都没有强调一点,下面以红色标示,基础国际化知识请先参考MSDN相关章节,关键 ...

  8. 基于visual Studio2013解决面试题之0410计算二进制中1的个数

     题目

  9. [置顶] 64位Win2008_VS2012使用ODP.NET遭遇问题和解决办法

    最近为使用Oracle11G数据库做个快速开发的小程序,使用64位Win2008+Vs2012环境,结果碰壁连环,幸好不算太笨,终于解决了,特记录一下. 测试环境: Oracle11g (11.2.0 ...

  10. 使用nginx的rewrite实现代理指定文件夹命令方法

    使用nginx的rewrite实现代理指定文件夹命令方法 使用nginx代理Tomcat,Tomcat公布web的时候通常都是带着项目名称的. 比方项目名称为"aven".那么公布 ...