Codeforces 358 D. Dima and Hares
来源:互联网 发布:蜘蛛池平台源码 编辑:程序博客网 时间:2024/06/05 01:51
dp[i][0]表示i号兔子先于i-1号兔子喂食,dp[i][1]反过来.
倒着DP
/** * 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]); }}
1 0
- 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)
- Codeforces 358D. Dima and Hares (DP)
- Codeforces 208 div2 D. Dima and Hares
- D. Dima and Hares----dp
- Codeforces Round #208 (Div. 2) D. Dima and Hares
- Codeforces Round #208 (Div. 2)D. Dima and Hares
- CF-358D-Dima and Hares【T^T+*^*】
- CF 358 D Dima and Hares(dp)
- 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
- codeforces 584D Dima and Lisa
- java实现直接插入排序
- git 如何创建你自己的Git服务器
- 使用ArcGIS Server发布我们的数据
- html超级链接(看张鹏老师的视频课程后所总结的)
- Strategy Pattern策略模式
- Codeforces 358 D. Dima and Hares
- 打基础自然是厚积薄发,这样的话我一般推荐下面四本书
- Buildroot 用法
- 基于jdk动态代理的实现与源码解析
- 【郁闷】表示原来的博客抽了
- java把文件写入内存---输出字节流
- SQL Server 2014附加数据库失败,错误5120的解决方法之一
- Minimum Path Sum
- 步入c++