大意: 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. SSH端口转发详解

    正文 一.SSH端口转发简介 SSH会自动加密和解密所有SSH客户端与服务端之间的网络数据.但是,SSH还能够将其他TCP端口的网络数据通SSH链接来转发,并且自动提供了相应的加密及解密服务.这一过程 ...

  2. BZOJ2208连通数

    还是挺简单的tarjan. 判断时可能重复,直接bitset搞定. 首先tarjan缩点,每个scc的内部肯定能互相到达,更一下,而且一个scc里的各个点的贡献肯定是一样的,topsort,更新答案就 ...

  3. 解决Vue在IE中报错出现不支持=>等ES6语法和“Promise”未定义等问题

    在做VUE项目中大家可能会发现除了IE内核浏览器之外项目都能正常显示,但是到IE就萎了,这主要是IE不支持ES6的原因. 要解决这个我们要先引入browser.js,这样你可以使用ES2015(jav ...

  4. SQLSTATE[HY000] [2002] Connection refused

    //域名绑定到模块 '__domain__' => [ 'admin' => 'admin', 'post' => 'api', 'user' => 'index', 'www ...

  5. String,int,Integer之间的转换

    public class Test{ public static void main(String[] args) { //int转换成Integer Integer in = new Integer ...

  6. 1、WebSphere Application Server的下载以及安装

    最近在做农行相关的项目,我们的后台需要发布到农行WebSphere Application Server上,因此学习一下: 一.WebSphere 是什么? WebSphere 为 SOA (面向服务 ...

  7. Android studio 项目支持JNI方法

    步骤: 1. build.gradle 配置如下,主要两项 ndk 和 sourceSets apply plugin: 'com.android.application' android { com ...

  8. Linux命令之文件和目录操作命令(一)—— ls

    本文介绍了ls命令的最常用法. 1.用法: ls [选项][目录名或文件名] 2.选项: -l 使用长格式显示目录或文件的详细信息 -a 显示隐藏文件 -h 人性化显示文件或目录的大小 -d 显示目录 ...

  9. linux/windows/Mac平台生成随机数的不同方法

    linux平台,使用rand.Seed() //rand_linux.go package main import ( "math/rand" "time" ) ...

  10. Apache POI读取Excel

    1.pom.xml配置文件 <!-- 配置Apache POI --> <dependency> <groupId>org.apache.poi</group ...