cf 762D. Maximum path
天呢,好神奇的一个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的更多相关文章
- Codeforces 762D Maximum path 动态规划
Codeforces 762D 题目大意: 给定一个\(3*n(n \leq 10^5)\)的矩形,从左上角出发到右下角,规定每个格子只能经过一遍.经过一个格子会获得格子中的权值.每个格子的权值\(a ...
- CodeForces 762D Maximum path
http://codeforces.com/problemset/problem/762/D 因为是3*n很巧妙的地方是 往左走两步或更多的走法都可以用往回走以一步 并走完一列来替换 那么走的方法就大 ...
- [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. ...
- [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 ...
- 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 ...
- 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 ...
- 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 ...
- [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 ...
- 【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 ...
随机推荐
- js中每隔一段时间执行一次
window.setInterval("flushs()",1000);
- siblings() 获取同胞元素的用法
1. $("h2").siblings().css({"color":"red","border":"2px ...
- MySql数据库慢查询
一.什么是数据库慢查询? 数据库慢查询,就是查询时间超过了我们设定的时间的语句. 可以查看设定的时间: 默认的设定时间是10秒.也可以自己根据实际项目设定. set long_query_time=0 ...
- ADO.NET基础必背知识
DO.NET 由.Net Framework 数据提供程序和DataSet 两部分构成. .NET FrameWork 是 Connection 连接对象 Command 命令对象 DataRe ...
- C#中File和FileStream的用法----转载
C#中File和FileStream的用法原创 忆汐辰 发布于2019-04-10 11:34:23 阅读数 5841 收藏展开 在近期的工作过程中发现自己的基础比较薄弱,所以最近在恶补基础知识.下面 ...
- 如何确定Redis集群中各个节点的主从关系
1.首先通过命令(以192.168.203.141为例,-c代表集群的意思) ./redis-cli -h 192.168.203.141 -p 8001 -c 2.然后在输入 cluster no ...
- Day8 - C - Largest Rectangle in a Histogram HDU - 1506
A histogram is a polygon composed of a sequence of rectangles aligned at a common base line. The rec ...
- BSD socket编程学习
1.socket简介 BSD是实现TCP/IP协议通信的软件系统,socket是应用编程接口,为app提供使用TCP/IP协议通信的接口. 网络层IP提供点到点服务(IP地址标识),传输层TCP和UD ...
- 连续(Continuity) - 有界(Bounded) - 收敛(Convergence)
连续(Continuity) 所有点连续 -> 一致连续 (uniform continuity) -> 绝对连续 -> 李普希兹连续(Lipschitz) 弱 ...
- 十七 Ajax&校验用户名功能
Ajax: 即"Asynchronous JavaScript And XML", 异步JavaScript和XML , 是指一种创建的交互式页面应用的网页开发技术,它并不是新的技 ...