题目戳这里

首先明确一点,数字最多往左走一次,走两次肯定是不可能的(因为只有\(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. PHPPCRE正则解析

    一.前言 前面的博客里,有对字符集的解析.这里就不是字符集的事儿了,在PHP中很多函数的处理默认是unicode中的UTF-8编码格式.那么废话不多说,直接开始正题. 二.PHP函数mb_split解 ...

  2. sqlite3 简单实用方法

    打开数据库:sqlite3.exe test.db 显示所有表: .tables 退出 sqlite3:.quit 还有个问题,已经打开一个数据库文件了. 不知道如何在不退出命令行的情况下,更换另一个 ...

  3. mysql 5.7 配置初始化及修改 ROOT 用户密码

    1.修改配置文件 my.ini 放在 mysql\bin [mysqld] basedir=C:\Mysql datadir=C:\Mysql\data port=3306 # server_id = ...

  4. 用状态机表示SFC中的并行分支

    过去一直认为,状态机表示SFC会不会是任务复杂化,这次简单实验了一下,感觉还可以.请看下面的控制. 在SFC中,A和B是一对并行分支,汇合后转移到C分支中,怎么了用状态机表示呢?这里我们在状态机里分别 ...

  5. zabbix配置报警媒介-用户-动作-邮件脚本触发mailx邮件报警

    2018-09-16更新,新版本zabbix不需要使用脚本发送邮件,在zabbix web界面直接配置就可以 配置邮件参数,测试发送邮件 确认安装相关服务,centos7默认安装 [root@VM_1 ...

  6. MinGW安装图文教程以及如何配置C语音编程环境

    MinGW安装图文教程以及如何配置C语音编程环境 转载自:http://www.jb51.net/softjc/192017.html MinGW 是一组包含文件和端口库,其功能是允许控制台模式的程序 ...

  7. 云计算之路-阿里云上:“黑色1秒”问题与2009年Xen一个补丁的故事

    在之前对“黑色1秒”问题的分析博文中,我们将最大嫌疑对象锁定在了Xen,在这篇博文我们将从Xen的角度进行分析.也许有人会问,为什么不知道天多高地多厚地去研究不属于自己范围的问题?只因我们对一个问题的 ...

  8. iOS笔记054 - 核心动画

    注意事项 :locationInView和translationInView // 返回相对于控件自身内部触摸点的位置 [pan locationInView:self]; // 返回两个触摸点之间的 ...

  9. github 初始化操作小记

     Git作为一种越来越重要的工具,github又如此流行,现在就简单记录一下git的基础操作,希望能帮助大家快速体验入门! 1 查看本地是否存在”公钥”和”私钥” 如果没有,则执行: ssh-keyg ...

  10. QC的使用学习(三)

    一.需求转换测试 1.自动转换方法: (1)将最底层的子需求转换成设计步骤:即将最底层的子要求转换成测试用例的步骤. (2)将最底层的子要求转换成测试:即将最底层的要求转换成单个测试用例(建议使用) ...