题目戳这里

首先明确一点,数字最多往左走一次,走两次肯定是不可能的(因为只有\(3\)行)。

然后我们用\(f_{i,j}\)表示前\(i\)行,第\(i\)行状态为\(j\)的最优解。(\(j\)表示从第一,二,三,行出来,或者是朝左走了)。

方程应该也好YY。

#include<iostream>
#include<cstdio>
#include<cstdlib>
using namespace std; typedef long long ll;
const int maxn = 100010; const ll inf = 1LL<<60;
int N; ll f[maxn][4],A[4][maxn]; inline int gi()
{
char ch; int ret = 0,f = 1;
do ch = getchar(); while (!(ch >= '0'&&ch <= '9')&&ch != '-');
if (ch == '-') f = -1,ch = getchar();
do ret = ret*10+ch-'0',ch = getchar(); while (ch >= '0'&&ch <= '9');
return ret*f;
} int main()
{
freopen("762D.in","r",stdin);
freopen("762D.out","w",stdout);
N = gi();
for (int i = 1;i <= 3;++i) for (int j = 1;j <= N;++j) A[i][j] = gi()+A[i-1][j];
for (int i = 0;i <= N;++i) for (int j = 0;j < 4;++j) f[i][j] = -inf;
f[0][1] = 0;
for (int i = 1;i <= N;++i)
{
for (int j = 1;j <= 3;++j)
for (int k = 1;k <= 3;++k) f[i][j] = max(f[i-1][k]+A[max(j,k)][i]-A[min(j,k)-1][i],f[i][j]);
f[i][1] = max(f[i][1],f[i-1][0]+A[3][i]);
f[i][3] = max(f[i][3],f[i-1][0]+A[3][i]);
f[i][0] = max(f[i][0],max(f[i-1][1],f[i-1][3])+A[3][i]);
}
cout << f[N][3] << endl;
fclose(stdin); fclose(stdout);
return 0;
}

CF762D Maximum Path的更多相关文章

  1. 题解 CF762D Maximum path

    题目传送门 Description 给出一个 \(3\times n\) 的带权矩阵,选出一个 \((1,1)\to (3,n)\) 的路径使得路径上点权之和最大. \(n\le 10^5\) Sol ...

  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. NOIP模拟 candy

    题目描述 一天,小 DD 决定买一些糖果.他决定在两家不同的商店中买糖果,来体验更多的口味. 在每家商店中都有 nn 颗糖果,每颗糖果都有一个权值:愉悦度,代表小 DD 觉得这种糖果有多好吃.其中,第 ...

  2. hadoop搭建----centos免密码登录、修改hosts文件

    分布式系统在传输数据时需要多台电脑免密码登录 如:A(192.168.227.12)想ssh免密码登录到B(192.168.227.12),需要把A的公钥文件(~/.ssh/id_rsa.pub)里内 ...

  3. ffmpeg使用笔记

    1.从mp4中提取h264:ffmpeg -i 264.mp4 -codec copy -bsf h264_mp4toannexb -f h264 output.h2642.从mp4中提取hevc:f ...

  4. gp的纯属意外的意外

    一不小心,把方法都传过去了,一脸蒙蔽说的就是我,啊哈哈哈啊哈

  5. 【转载】[Elasticsearch]ES入门

    传送门:http://www.cnblogs.com/xing901022 ES即简单又复杂,你可以快速的实现全文检索,又需要了解复杂的REST API.本篇就通过一些简单的搜索命令,帮助你理解ES的 ...

  6. 1 opencv2.4 + vs2013

    http://blog.csdn.net/poem_qianmo/article/details/19809337 1.安装vs2013 2.安装opencv2.4 下载地址:https://sour ...

  7. 深度学习之卷积神经网络CNN

    转自:https://blog.csdn.net/cxmscb/article/details/71023576 一.CNN的引入 在人工的全连接神经网络中,每相邻两层之间的每个神经元之间都是有边相连 ...

  8. lnmp操作

    LNMP 1.2+状态管理: lnmp {start|stop|reload|restart|kill|status}LNMP 1.2+各个程序状态管理: lnmp {nginx|mysql|mari ...

  9. [转] Bash脚本:怎样一行行地读文件(最好和最坏的方法)

    用bash脚本读文件的方法有很多.请看第一部分,我使用了while循环及其后的管道命令(|)(cat $FILE | while read line; do … ),并在循环当中递增 i 的值,最后, ...

  10. 1,理解java中的IO

    IO中的几种形式 基于字节:InputStream.OutputStream 基于字符:Writer.Reader 基于磁盘:File 基于网络Socket   最终都是字节操作,字符到字节要编码转换 ...