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. spring MVC 如何获取session并实现传值到前台

    后台获取session: @RequestMapping("/usrlogin") public ModelAndView usrlogin(@RequestParam Strin ...

  2. 一个故事讲清楚NIO(转)

    转载请引用:一个故事讲清楚NIO 假设某银行只有10个职员.该银行的业务流程分为以下4个步骤: 1) 顾客填申请表(5分钟): 2) 职员审核(1分钟): 3) 职员叫保安去金库取钱(3分钟): 4) ...

  3. Creating Spatial Indexes(mysql 创建空间索引 The used table type doesn't support SPATIAL indexes)

    For MyISAM tables, MySQL can create spatial indexes using syntax similar to that for creating regula ...

  4. 黑马day16 jquery&amp;层次选择器

    假设想通过DOM元素之间的层次关系来获取特定元素,比如后代元素,子元素,相邻元素,兄弟元素等,则须要使用层次选择器. 1 .ancestor descendant 使用方法: $("form ...

  5. IOS系统对fixed定位支持不好的解决方法

    问题: IOS 中所有浏览器,当页面上的输入框获得焦点时,呼出键盘. 页面底部的导航栏(position:fixed)会被键盘顶到页面的中间. 而当输入框失去焦点时,导航栏停留在页面中间,造成页面错乱 ...

  6. How to install vim on linux

    前几日了解到 vim 文本编辑器,据说很强大,使用起来效率很高,今天怀着很好奇的心理,学习了一下vim编辑器的下载安装方法,在此详细介绍一下安装vim编辑器的几种常用方法: 第一种方法就是在 Ubun ...

  7. RAC 11.2.0.4 安装 遇到 INS-06001

    今天安装11.2.0.4的grid软件,在配置passwordless SSH的时候,点击setup 出现此错误 开始网上搜了一把.说什么的都有,什么系统bug啊什么的 但是我另外一套rac却很正常就 ...

  8. linux-0.11抠代码-bootsect

    //bootfun.s .global asm_message .global asm_memmove .global asm_readsector .global asm_checkLBA .cod ...

  9. linux下crontab的使用方法

    <span style="font-size:14px;">在Linux中任务可以被配置在指定的时间段.指定的日期.或系统平均载量低于指定的数量时自动运行. cront ...

  10. axure篇

    QQ:1187362408 欢迎技术交流和学习 axure篇(axure rp 7.0): TODO: 1.汉化组件及菜单选项 界面组件汉化: 菜单汉化: 2,了解axure 控制器中各项功能区中的菜 ...