大意: 3*n矩阵, 求从(1,1)->(3,n)路径最大点权和.

核心观察是每个点回头一定不会超过1, 这是因为只有三行, 若回头两格一定是$9$个位置全走, 显然可以找到一种只会头一格的方案与回头两格的方案等价.

#include <iostream>
#include <sstream>
#include <algorithm>
#include <cstdio>
#include <math.h>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <string.h>
#include <bitset>
#define REP(i,a,n) for(int i=a;i<=n;++i)
#define PER(i,a,n) for(int i=n;i>=a;--i)
#define hr putchar(10)
#define pb push_back
#define lc (o<<1)
#define rc (lc|1)
#define mid ((l+r)>>1)
#define ls lc,l,mid
#define rs rc,mid+1,r
#define x first
#define y second
#define io std::ios::sync_with_stdio(false)
#define endl '\n'
#define DB(a) ({REP(__i,1,n) cout<<a[__i]<<' ';hr;})
using namespace std;
typedef long long ll; const int N = 1e6+10;
int n;
ll a[3][N], dp[3][N], s[N]; int main() {
scanf("%d", &n);
REP(i,0,2) REP(j,1,n) scanf("%lld",a[i]+j);
REP(i,1,n) s[i]=a[0][i]+a[1][i]+a[2][i];
dp[0][1]=a[0][1],dp[1][1]=a[0][1]+a[1][1],dp[2][1]=s[1];
REP(i,2,n) {
dp[0][i]=max({dp[0][i-1],dp[1][i-1]+a[1][i],dp[2][i-1]+a[2][i]+a[1][i]});
dp[0][i]=max(dp[0][i],dp[2][i-2]+s[i-1]+a[2][i]+a[1][i]);
dp[0][i]+=a[0][i];
dp[2][i]=max({dp[2][i-1],dp[1][i-1]+a[1][i],dp[0][i-1]+a[0][i]+a[1][i]});
dp[2][i]=max(dp[2][i],dp[0][i-2]+s[i-1]+a[0][i]+a[1][i]);
dp[2][i]+=a[2][i];
dp[1][i]=max({dp[1][i-1],dp[0][i-1]+a[0][i],dp[2][i-1]+a[2][i]});
dp[1][i]+=a[1][i];
}
printf("%lld\n",dp[2][n]);
}

Maximum path CodeForces - 762D的更多相关文章

  1. Codeforces 762D Maximum path 动态规划

    Codeforces 762D 题目大意: 给定一个\(3*n(n \leq 10^5)\)的矩形,从左上角出发到右下角,规定每个格子只能经过一遍.经过一个格子会获得格子中的权值.每个格子的权值\(a ...

  2. [LeetCode] Binary Tree Maximum Path Sum 求二叉树的最大路径和

    Given a binary tree, find the maximum path sum. The path may start and end at any node in the tree. ...

  3. [leetcode]Binary Tree Maximum Path Sum

    Binary Tree Maximum Path Sum Given a binary tree, find the maximum path sum. The path may start and ...

  4. LeetCode(124) Binary Tree Maximum Path Sum

    题目 Given a binary tree, find the maximum path sum. For this problem, a path is defined as any sequen ...

  5. LeetCode124:Binary Tree Maximum Path Sum

    题目: Given a binary tree, find the maximum path sum. The path may start and end at any node in the tr ...

  6. leetcode 124. Binary Tree Maximum Path Sum

    Given a binary tree, find the maximum path sum. For this problem, a path is defined as any sequence ...

  7. [lintcode] Binary Tree Maximum Path Sum II

    Given a binary tree, find the maximum path sum from root. The path may end at any node in the tree a ...

  8. 【leetcode】Binary Tree Maximum Path Sum

    Binary Tree Maximum Path Sum Given a binary tree, find the maximum path sum. The path may start and ...

  9. 【leetcode】Binary Tree Maximum Path Sum (medium)

    Given a binary tree, find the maximum path sum. The path may start and end at any node in the tree. ...

随机推荐

  1. SRS之SrsRtmpConn::service_cycle详解

    1. SrsRtmpConn::service_cycle 当服务器在 conn 线程的开始调用 connect_app 函数接收并解析客户端发送的 connect 消息后,调用该 service_c ...

  2. Druid连接池(无框架)

    关于连接池有不少技术可以用,例如c3p0,druid等等,因为druid有监控平台,性能在同类产品中算top0的.所以我采用的事druid连接池. 首先熟悉一个技术,我们要搞明白,为什么要用他, 他能 ...

  3. python正则表达式解析(re)

    正则表达式的使用方法主要有4种: re.search(进行正则匹配), re.match(从头开始匹配)  re.findall(找出所有符合条件的字符列表)  re.split(根据条件进行切分)  ...

  4. 利用uniGUI中的TUniPageControl实现多页面

    远行效果: 实现代码: procedure TfrmMain.OpenForm(Caption,FormClassName:string);var  i:integer;  sheet:TUniTab ...

  5. LC 539. Minimum Time Difference

    Given a list of 24-hour clock time points in "Hour:Minutes" format, find the minimum minut ...

  6. Carousel 走马灯

    在有限空间内,循环播放同一类型的图片.文字等内容 基础用法 适用广泛的基础用法 结合使用el-carousel和el-carousel-item标签就得到了一个走马灯.幻灯片的内容是任意的,需要放在e ...

  7. Steps 步骤条

    引导用户按照流程完成任务的分步导航条,可根据实际应用场景设定步骤,步骤不得少于 2 步. 基础用法 简单的步骤条. 设置active属性,接受一个Number,表明步骤的 index,从 0 开始.需 ...

  8. C++输入输出流加速器,关闭同步流,ios::sync_with_stdio(false)和 cin.tie(0)

    leetcode练习时,总会发现运行时间短的代码都会有类似: static int x=[](){ std::ios::sync_with_stdio(false); cin.tie(NULL); ; ...

  9. jenkins+git+gitlab+ansible实现持续集成自动化部署

    一.环境配置 192.168.42.8部署gitlab,节点一 192.168.42.9部署git,Jenkins,ansible服务器 192.168.42.10节点二 二.操作演示 ①gitlab ...

  10. 使用gimp画线、矩形、圆等

    使用gimp画线.矩形.圆等 https://blog.csdn.net/tody_guo/article/details/7628508 2012年06月03日 19:08:47 Tody Guo  ...