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 ...
随机推荐
- Redis 的使用
1. 概念: redis是一款高性能的NOSQL系列的非关系型数据库 1.1.什么是NOSQL NoSQL(NoSQL = Not Only SQL),意即"不仅仅是SQL",是一 ...
- 【JAVA蓝桥杯】基础练习2 十六进制转十进制
资源限制 时间限制:1.0s 内存限制:512.0MB 问题描述 从键盘输入一个不超过8位的正的十六进制数字符串,将它转换为正的十进制数后输出. 注:十六进制数中的10~15分别用大写的英文字母A ...
- java并发AtomicReference
java并发AtomicReference AtomicReference的作用 已经介绍过AtomicInteger,AtomicIntegerArray,AtomicReference是针对对象的 ...
- Android 如何从系统图库中选择图片
转:http://blog.csdn.net/tody_guo/article/details/7560270 这几天我都在做Android的App,同时学习它的API,我将分享一些我学到的东西,比如 ...
- 前端Cannot read property 'disabled' of null 问题解决
就是在项目中,控制台一直在报这个错,一直没找到是什么问题, 后来经过一番排查,发现是 因为在页面中使用了el-dropdown,但是在这个标签里面没有设置它的子元素,所以会报错,解决的方法就是在el- ...
- Kubernetes——滚动更新和数据管理
k8s——滚动更新滚动更新就是一次只更新一小部分副本,更新成功之后再更新更多的副本,最终完成所有副本的更新.滚动更新最大的好处是零停机,整个更新的过程中始终有副本运行,从而保证了业务的连续性.kube ...
- codeforces 962 F Simple Cycles Edges
求简单环,即求点=边数的点双分量,加上判断点和边的模板即可 (简单环模板,区分与点双缩点) ; ], edgecnt, dfn[maxm], low[maxm], bcc_cnt, bccnum[ma ...
- Redis散列表类型
散列类型(hash)的键值也是一种字典结构,其存储了字段(field)和字段值的映射,但字段值只能是字符串,不支持其他的数据类型. 一个散列类型键可以包含至多2^32 -1个字段. 命令 赋值 HSE ...
- Sweet Round 1题解
感谢各位参赛者,所有的题解如下: T1 syx的奖励 这题明显是签到题了吧,随便猜猜结论就A掉了 先说怎么做吧,把所有的可走的数gcd起来,然后再与n求gcd 如果为1,则输出n,若不为1,则输出-1 ...
- 吴裕雄--天生自然JAVA数据库编程:ResultSet接口
import java.sql.Connection ; import java.sql.DriverManager ; import java.sql.SQLException ; import j ...