大意: 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. 04.重建二叉树 (Java)

    题目描述 输入某二叉树的前序遍历和中序遍历的结果,请重建出该二叉树.假设输入的前序遍历和中序遍历的结果中都不含重复的数字.例如输入前序遍历序列{1,2,4,7,3,5,6,8}和中序遍历序列{4,7, ...

  2. fastadmin后台视频文件上传,受限制,修改php.ini配置即可

    post_max_size = 50M(根据情况)upload_max_filesize  = 50M(根据情况)

  3. java加密算法相关

    简介 RSA公钥加密算法是1977年由罗纳德·李维斯特(Ron Rivest).阿迪·萨莫尔(Adi Shamir)和伦纳德·阿德曼(Leonard Adleman)一起提出的.1987年首次公布,当 ...

  4. android canvas drawtext 字高

    Paint pFont = new Paint(); Rect rect = new Rect(); pFont.getTextBounds("豆", 0, 1, rect); L ...

  5. ipv4 ipv6 求字符串和整数一一映射的算法 AmazonOrderId

    字符串和整数一一映射的算法 公司每人的英文名不同,现在给每个英文名一个不同的数字编号,怎么设计? 走ipv4/6  2/32 2/128就够了,把“网段”概念对应到“表或库”,ip有a_e5类,这概念 ...

  6. LC 965. Univalued Binary Tree

    A binary tree is univalued if every node in the tree has the same value. Return true if and only if ...

  7. vue.js-动态绑定class 利用index实现导航

    <template> <div class="stock"> <div class="buin_leftcont nav_ctrl" ...

  8. python-Web-django-ajax分页

    views: from django.shortcuts import HttpResponse,redirect,render from app01.models import * import j ...

  9. GPL,BSD,Apache三个开源协定的大体联系及区别

    开源许可证GPL.BSD.MIT.Mozilla.Apache和LGPL的区别 以下是上述协议的简单介绍: BSD开源协议 BSD开源协议是一个给于使用者很大自由的协议.基本上使用者可以"为 ...

  10. IE11兼容IE8的设置

    我们在使用ie11浏览器的时候,有些网站的兼容性不是太好,这个时候就要设置下ie11的兼容性了.那么ie11浏览器怎么设置兼容IE8呢?下面就让小编给大家介绍一下吧. 首先我们打开电脑里面的ie11浏 ...