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相关推荐
- Codeforces Round #208 (Div. 2)D. Dima and Hares
原题连接:http://codeforces.com/contest/358/problem/D 题目大意:有n个兔子排成一排,给第i个兔子喂食后,在其左右两只兔子均未被喂食是获得ai的愉悦值,有一个 ...
- cf D. Dima and Hares
http://codeforces.com/contest/358/problem/D 题意:ai代表相邻的两个野兔都没有吃食物情况下的快乐系数,bi代表的是在相邻的两个野兔中有一个吃到食物的快乐系数 ...
- linux安装eclipse运行web,Linux安装Tomcat,运行Eclipse,web项目
到官网下载:https://tomcat.apache.org/download-80.cgi 在这里是8.5.39版本 下载tar,gz 提取解压后,我这里是放到opt目录下 cd 切换目录 / ...
- 【MZ】CF 358D - 358E #209 (Div. 2)
D. Dima and Hares problem 输入n (1 ≤ n ≤ 3000) a1 a2 ... an. b1, b2, ..., bn. c1, c2, ..., cn. n只兔 ...
- Codeforces Round #167 (Div. 1) C. Dima and Horses(BFS+贪心)
题目大意 有 n(1≤n≤3*105) 匹马,每条马都有几个敌人(不超过 3 个),现在要求把这些马分成两部分(允许一部分中没有一条马),使得对于每条马,和它在同一部分中的敌人的数量不超过1个 给出了 ...
- CODEFORCES 272C Dima and Staircase 细节理解题+简单技巧
传送门:http://codeforces.com/problemset/problem/272/C C. Dima and Staircase time limit per test 2 secon ...
- codeforces 400D Dima and Bacteria 并查集+floyd
题目链接:http://codeforces.com/problemset/problem/400/D 题目大意: 给定n个集合,m步操作,k个种类的细菌, 第二行给出k个数表示连续的xi个数属于i集 ...
- Codeforces Round #358 (Div. 2) A. Alyona and Numbers 水题
A. Alyona and Numbers 题目连接: http://www.codeforces.com/contest/682/problem/A Description After finish ...
- Codeforces - 272C Dima and Staircase(思维)
题目链接---- Dima's got a staircase that consists of n stairs. The first stair is at height a1, the seco ...
最新文章
- PubChem分子库
- Redis遍历所有key的两个命令 -- KEYS 和 SCAN
- 查看mysql5.7默认密码_mysql-5.7安装部署+MySQL5.7初始密码查看及重置
- java api文档_JAVA浏览器控件JxBrowser v7.3上线!最新API文档打包带走
- nexus下载 通过官网下载
- 门禁卡读写器—把手机秒变门禁卡与自己复制门禁卡
- linux centos下安装R语言,Centos6下安装R语言教程
- ALM需求跟踪矩阵导出出错解决
- Joomla 插件 attachments 使用时出现不支持ZIP文件上传的错误
- js怎样判断是不是整数
- killer queen ctf
- python _foo __foo
- python熊猫图案_熊猫备忘单–适用于数据科学的Python
- 阿尔萨斯监控平台普罗米修斯监控平台对服务器资源的监控
- Android Studio 类微信界面的制作
- r语言 svycoxph_R语言-Cox比例风险模型
- Linux Ubuntu系统设置成中文语言
- 风丘科技为您提供车载以太网解决方案
- HTML+H5基础——常用标签
- 解决小程序Input框输入文字后触摸并滚动屏幕不松开,input内文字一起滚动问题