思路:

 dp[i][0] 代表取的时候左边没有

dp[i][1] 代表取的时候右边没有

dp[i][2] 代表取的时候左右都没有

dp[i][3] 代表取的时候左右都有

然后自己转移吧= =、

注意两个区间端点:

 如果旁边有取a[i], 如果没有取b[i]。
 只有一个的时候取a[i]。。。。
太狗了,这题意!
#include<bits/stdc++.h>
using namespace std;
typedef __int64 LL;
const int INF=0x3f3f3f3f; int dp[3005][4];
int a[3005];
int b[3005];
int c[3005]; void DP(int n)
{
if(n==1)
{
printf("%d\n",a[1]);
return;
}
memset ( dp , -0x3f , sizeof ( dp ) );
dp[1][0]=a[1];
dp[1][2]=b[1];
dp[1][1]=-INF;
dp[1][3]=-INF; for(int i=2;i<n;i++)
{
dp[i][0]=max(dp[i-1][0]+b[i],dp[i-1][3]+b[i]);
dp[i][1]=max(dp[i-1][1]+b[i],dp[i-1][2]+b[i]);
dp[i][2]=max(dp[i-1][0]+c[i],dp[i-1][3]+c[i]);
dp[i][3]=max(dp[i-1][1]+a[i],dp[i-1][2]+a[i]);
} dp[n][1]=max(dp[n-1][1]+a[n],dp[n-1][2]+a[n]);
dp[n][2]=max(dp[n-1][0]+b[n],dp[n-1][3]+b[n]); printf("%d\n",max(dp[n][1],dp[n][2]));
} void solve()
{
int n;
scanf("%d",&n);
for(int i=1;i<=n;i++)
scanf("%d",&a[i]);
for(int i=1;i<=n;i++)
scanf("%d",&b[i]);
for(int i=1;i<=n;i++)
scanf("%d",&c[i]); DP(n);
} int main()
{
solve();
return 0;
}
/*
4
1 2 3 4
4 3 2 1
0 1 1 0
*/

Codeforces 358D【DP】的更多相关文章

  1. CodeForces 106C 【DP】

    题意: n g dough  m种商品? 每种有ai stuffing, 拿bi stuffing + ci dough -> di tugriks rest c0 dough -> d0 ...

  2. CodeForces 761C 【DP】

    总结:能这么DP就这么写! 多练位运算标记. #include<bits/stdc++.h> using namespace::std; const int N=55; const int ...

  3. CodeForces 13C【DP】

    题意: 给你n个数,每次只能让一个数+1,或者-1,目标是最终使这个序列构成一个非递减的序列: n是5e3,复杂度n^2内.值是1e9: 思路: 可以发现子结构是保证一个区间的非递减, 如果只是dp[ ...

  4. CodeForces 687C【DP】

    题意: 给你n个数,然后让这些数相加组合,然后在这些组合的数里可以再相加组合搞出给定 k,输出这些组合的数. 思路: DP. //在枚举到第i个coin的时,dp[i][j],i 肯定能被a[i]组合 ...

  5. CodeForces 429B【dp】

    题意: 在一个n*m的矩阵中有两只虫子,一只从左上角向右下角移动,另外一只从左下角向右上角移动. 要求: 1.第一只虫子每次只能向左或者向下移动一格,另外一只只能向上或者向右移动一格. 2.两只虫子的 ...

  6. [CodeForces - 1225E]Rock Is Push 【dp】【前缀和】

    [CodeForces - 1225E]Rock Is Push [dp][前缀和] 标签:题解 codeforces题解 dp 前缀和 题目描述 Time limit 2000 ms Memory ...

  7. Kattis - honey【DP】

    Kattis - honey[DP] 题意 有一只蜜蜂,在它的蜂房当中,蜂房是正六边形的,然后它要出去,但是它只能走N步,第N步的时候要回到起点,给出N, 求方案总数 思路 用DP 因为N == 14 ...

  8. HDOJ 1423 Greatest Common Increasing Subsequence 【DP】【最长公共上升子序列】

    HDOJ 1423 Greatest Common Increasing Subsequence [DP][最长公共上升子序列] Time Limit: 2000/1000 MS (Java/Othe ...

  9. HDOJ 1501 Zipper 【DP】【DFS+剪枝】

    HDOJ 1501 Zipper [DP][DFS+剪枝] Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Ja ...

随机推荐

  1. php判断某字符串是否不以数字或其他特殊字符开头

    if(preg_match("/^[^\d-.,:]/",$addr)){ echo $addr.'不是数字或其他特殊字符开头'; }

  2. Windows8-x64 VMWare安装Linux CentOS6-x64

    本文參考了:http://www.cnblogs.com/seesea125/archive/2012/02/25/2368255.html 其内容相当具体,以至于我还没依照其步骤做完.系统就已经安装 ...

  3. 基于注解的Sping AOP详解

    一.创建基础业务 package com.kang.sping.aop.service; import org.springframework.stereotype.Service; //使用注解@S ...

  4. 九度OJ 1087:约数的个数 (数字特性)

    时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:7349 解决:2306 题目描述: 输入n个整数,依次输出每个数的约数的个数 输入: 输入的第一行为N,即数组的个数(N<=1000) ...

  5. Package md5 implements the MD5 hash algorithm as defined in RFC 1321 base64

    https://golang.google.cn/pkg/crypto/md5/ Go by Example 中文:Base64编码 https://books.studygolang.com/gob ...

  6. Red Black Tree java.util.TreeSet

    https://docs.oracle.com/javase/9/docs/api/java/util/SortedMap.html public interface SortedMap<K,V ...

  7. Android笔记之在onCreate中执行View.getWidth()和View.getHeight()得到的结果均为0的解决方案

    方案有多种,只记一种 使用View.post(Runnable) 示例如下 Log如下 由log可知,View.post(Runnable)是异步的

  8. checkbox复选框的使用

    复选框: <input type="checkbox" name="favor" value="唱歌"/>唱歌    <i ...

  9. github for unity

  10. json Gson

    package com.example.volleylearn; import java.util.ArrayList; import java.util.List; import java.util ...