思路:

 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. windows常用命令(转载)

    1.最基本,最常用的,测试物理网络的  ping 192.168.0.8 -t ,参数-t是等待用户去中断测试 2.查看DNS.IP.Mac等  A.Win98:winipcfg  B.Win2000 ...

  2. centos6.4中文输入法安装和切换(转载)

    1.用root登录,或者切换到root账户(su root): 2.yum install "@Chinese Support"; 3.exit: 4.System→prefere ...

  3. 左儿子右兄弟Trie UVA 11732 strcmp() Anyone?

    题目地址: option=com_onlinejudge&Itemid=8&category=117&page=show_problem&problem=2832&qu ...

  4. ASP.NET MVC4中ViewBag、ViewData和TempData的使用和区别

    一.说明 本文章主要是讲解asp.net mvc中ViewBag.ViewData和TempData的使用和区别,ViewBag.ViewData和TempData常常用于将action方法中的数据传 ...

  5. if __name__ == "__main__": 怎么理解?

    参考:https://www.cnblogs.com/Neeo/p/9504779.html 总结: 1.防止模块间调用时,执行被调用模块实例化执行,换句话说,就是不要执行调用模块原来实例化的内容 2 ...

  6. Redis persistence demystified

    https://redis.io/topics/persistence http://oldblog.antirez.com/post/redis-persistence-demystified.ht ...

  7. myeclipse查看项目在本地的路径

    打开myeclipse编译器,选择项目,右键:选择properties 在这一侧的搜索框中输入:resource Location即是项目的在本地的路径. 亲测好使.

  8. 【LeetCode】Construct Binary Tree from Preorder and Inorder Traversal

    Given preorder and inorder traversal of a tree, construct the binary tree. Note:You may assume that ...

  9. A Windows GUI for Appium

    A Windows GUI for Appium If you are new to Appium then please see the Getting started guide for more ...

  10. CSS动画硬件加速

    http://zencode.in/14.CSS%E5%8A%A8%E7%94%BB%E7%9A%84%E6%80%A7%E8%83%BD%E4%BC%98%E5%8C%96.html http:// ...