天呢,好神奇的一个DP23333%%%%%

因为1.向左走1格的话相当于当前列和向左走列全选

2.想做走超过1的话可以有上下走替代。而且只能在相邻行向左。

全选的情况只能从第1行和第3行转移,相反全选的情况也只能转移到第1行和第3行。

(大雾,DP太玄乎了,不是很懂2333)

 #include<bits/stdc++.h>
#define LL long long
#define N 100005
#define lowbit(x) x&(-x)
using namespace std;
inline int ra()
{
int x=,f=; char ch=getchar();
while (ch<'' || ch>'') {if (ch=='-') f=-; ch=getchar();}
while (ch>='' && ch<='') {x=x*+ch-''; ch=getchar();}
return x*f;
}
const LL INF=1e16;
LL f[N][];
int a[][N];
inline LL sum(int x, int l, int r)
{
if (l>r) swap(l,r);
LL ret=;
for (int i=l; i<=r; i++) ret+=a[i][x];
return ret;
}
int main()
{
int n=ra();
for (int i=; i<; i++)
for (int j=; j<=n; j++)
a[i][j]=ra();
for (int i=; i<=n; i++)
for (int j=; j<; j++)
f[i][j]=-INF;
f[][]=;
for (int i=; i<=n; i++)
{
for (int j=; j<; j++)
for (int k=; k<; k++)
f[i][j]=max(f[i][j],f[i-][k]+sum(i,j,k));
f[i][]=max(f[i][],f[i-][]+sum(i,,));
f[i][]=max(f[i][],f[i-][]+sum(i,,));
f[i][]=max(f[i][],max(f[i-][],f[i-][])+sum(i,,));
}
cout<<f[n][];
return ;
}

cf 762D. Maximum path的更多相关文章

  1. Codeforces 762D Maximum path 动态规划

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

  2. CodeForces 762D Maximum path

    http://codeforces.com/problemset/problem/762/D 因为是3*n很巧妙的地方是 往左走两步或更多的走法都可以用往回走以一步 并走完一列来替换 那么走的方法就大 ...

  3. [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. ...

  4. [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 ...

  5. 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 ...

  6. 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 ...

  7. 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 ...

  8. [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 ...

  9. 【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 ...

随机推荐

  1. SRSniffer抓包工具的使用

    1.打开SRSniffer软件 2.按照1-->2-->3依次点击 3.点击左侧的启动监听按钮 4.打开要记录api的软件,查看效果

  2. 堡垒机安装google-authenticator

    公司线上的使用机器不能让用户随意的登陆,所以就不能让开发随意的登陆到生产的机器的.于是就打算使用google-auth的验证方式呢. 如果google-auth的方式. 搭建google-authen ...

  3. git安装以及gitlib配置

    安装Git:详见http://www.cnblogs.com/xiuxingzhe/p/9300905.html 开通gitlab(开通需要咨询所在公司的gitlab管理员)账号后,本地Git仓库和g ...

  4. windows服务使用和控制启停

    https://www.cnblogs.com/mq0036/p/7875864.html

  5. java-jpa-criteriaBuilder使用

    一个复杂的查询例子(包含常用的所有查询方法) CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder(); //查询结果所 ...

  6. python中时间戳的探索

    声明 本文章只针对python3.6及以上版本. 问题提出 首先,我们先import一些必要模块: In [1]: from datetime import datetime, timezone, t ...

  7. 一 Java语言基础

    1 标识符: 用来标识类名.变量名.方法名.类型名.数组名.文件名的有效字符序列. 由字母.美元符.下划线.数字组成,不能以数字开头,如  int 6a = 1; 2 基本数据类型8个: 整数4个:字 ...

  8. 吴裕雄--天生自然PYTHON爬虫:爬虫攻防战

    我们在开发者模式下不仅可以找到URL.Form Data,还可以在Request headers 中构造浏览器的请求头,封装自己.服务器识别浏览器访问的方法就是判断keywor是否为Request h ...

  9. 【剑指Offer面试编程题】题目1503:二叉搜索树与双向链表--九度OJ

    题目描述: 输入一棵二叉搜索树,将该二叉搜索树转换成一个排序的双向链表.要求不能创建任何新的结点,只能调整树中结点指针的指向. 输入: 输入可能包含多个测试样例. 对于每个测试案例,输入的第一行为一个 ...

  10. java并发:初探消费者和生产者模式

    消费者和生产者模式 用继承Thread方式,用wait和notifyAll方法实现. 消费者和生产者模式的特点 1. 什么时候生产:仓库没有满的时候,生产者这可以生产,消费者也可以消费,仓库满的时候停 ...