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变成最大 ...
随机推荐
- C#版二维码生成器附皮肤下载
原文 C#版二维码生成器附皮肤下载 前言 本文所使用的二维码生成代码是谷歌开源的条形码图像处理库完成的,c#版的代码可去https://code.google.com/p/zxing/download ...
- css概述
前言 1.CSS cascading stylesheet 级联样式表 ,外观显示(页面内容显示的方式).CSS文档以.css作为后缀 2.w3c推荐页面文件定义 数据和结 ...
- [ACM] HDU 5083 Instruction (模拟)
Instruction Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Tota ...
- Java 自定义日志写入
/** * 将信息写入到日志 * @param content * @return * @throws IOException */ public static boolean writeLog(St ...
- LoadRunner监控数据库服务器
使用LoadRunner的数据库服务器资源监控器,可以在场景或会话步骤运行期间监控DB2.Oracle.SQL Server或Sybase数据库的资源使用率.在场景或会话步骤运行期间,使用这些监控器可 ...
- 【BOI2007】【BZOJ1176】Mokia
1176: [Balkan2007]Mokia Time Limit: 30 Sec Memory Limit: 162 MB Submit: 1059 Solved: 432 [Submit][St ...
- hdoj 1286 找新朋友 【数论之欧拉函数】
找新朋友 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submi ...
- 实现浏览器遗漏的原件 jQuery.selectCheckbox
工作中遇到了一个下拉需要实现checkbox的效果,如下图 或许网上已经有实现了,但简单的功能自己实现就好了, 结构 <div class="form-control-wrap&quo ...
- <input type=button> 跳转页面
打开新页面 标题" type="button" onclick='window.open("bedzhao.aspx")' /> 转换本页面 标 ...
- [置顶] 用mootools实现checkbox全选功能
全选时,所有的单个checkbox都要选中,反过来也可以实现 //全选按钮 $('chkall').addEvent('click',function(){ $$('input[name=" ...