Codeforces 208 div2 D. Dima and Hares
来源:互联网 发布:现货农产品分析软件 编辑:程序博客网 时间:2024/06/05 03:39
题目:Codeforces 208 div2 D. Dima and Hares
tag :dp
思路:dp[i][0] 表示i先于i+1 前 i 项的最大值
dp[i][1] 表示i后于i+1 前 i 项的最大值
注意:求最大值的时候要注意最后一项,如果单纯求max(dp[n][1],dp[n][0])就错了,因为dp[n][1]没有第n+1项
同时,当n=1的时候,答案唯一 a[1]
import java.math.BigInteger;import java.util.*;import static java.util.Arrays.sort;public class Main{ public static int max(int a,int b){ return a>b?a:b; } public static void main(String args[]){ Scanner cin=new Scanner(System.in); int n; int maxn=3010; int a[]=new int[maxn]; int b[]=new int[maxn]; int c[]=new int[maxn]; int[][] dp=new int[maxn][2]; while(cin.hasNext()){ n=cin.nextInt(); for(int i=1;i<=n;i++) a[i]=cin.nextInt(); for(int i=1;i<=n;i++) b[i]=cin.nextInt(); for(int i=1;i<=n;i++) c[i]=cin.nextInt(); if(n==1){ System.out.println(a[1]); continue; } Arrays.fill(dp[1],0); Arrays.fill(dp[0],0); dp[1][0]=a[1]; dp[1][1]=b[1]; for(int i=2;i<n;i++){ dp[i][0]=max(dp[i-1][0]+b[i],dp[i-1][1]+a[i]); dp[i][1]=max(dp[i-1][0]+c[i],dp[i-1][1]+b[i]); } int ans=max(dp[n-1][0]+b[n],dp[n-1][1]+a[n]); System.out.println(ans); } }}
- Codeforces 208 div2 D. Dima and Hares
- Codeforces Round #208 (Div. 2) D. Dima and Hares
- Codeforces Round #208 (Div. 2)D. Dima and Hares
- Codeforces 358 D. Dima and Hares
- Codeforces 358D Dima and Hares【dp】
- Codeforces 358D Dima And Hares DP
- codeforces 358D D. Dima and Hares(dp)
- codeforces 358D D. Dima and Hares(dp)
- D. Dima and Hares----dp
- Codeforces 358D. Dima and Hares (DP)
- CF-358D-Dima and Hares【T^T+*^*】
- CF 358 D Dima and Hares(dp)
- Codeforces #324 Div2 D.Dima and Lisa(三素数构造、哥德巴赫猜想)
- CodeForces 366D Dima and Trap Graph
- Codeforces 400 D. Dima and Bacteria
- CodeForces 400D Dima and Bacteria
- codeforces 400D - Dima and Bacteria
- Codeforces Round #324 D Dima and Lisa
- Linux下SVN服务器搭建(CentOS+Subversion)
- 对象析构谈—— delete this 的使用及注意事项
- DP分类题目 转载 《志当存高远》大神的 没有冒犯的意思 只是拿过来学习的
- Linux--线程编程
- 美团笔试题之抛硬币问题
- Codeforces 208 div2 D. Dima and Hares
- 确定一个Excel表格的最大行数和最大列数
- arm触屏获取触点坐标
- 第13周 函数的递归调用(1+2+3+4+5)
- 翻译官网 SpringAOP (1)
- 11月19日
- Linux 安装与多重引导摘要
- CentOS上面对查看svn的帮助信息
- VS调试技巧-汇编,逐语句,逐过程,跳出