题面

Having endured all the hardships, Lara Croft finally found herself in a room with treasures. To her surprise she didn't find golden mountains there. Lara looked around and noticed on the floor a painted table n × m panels in size with integers written on the panels.

题意

在一个\(n * m\)的矩阵中,第\(i\)取前\(c_i\)个元素,要求\(c1 > c2 < c3 > c4 < ...\) 求最后取到的元素和的最大值.

思路

\(dp[i][j]\) 表示第\(i\)行取\(j\)个元素的最大值.

在奇数行和偶数行按不同的顺序更新就行了.

#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<ctime> #define fuck(x) cerr<<#x<<" = "<<x<<endl;
#define debug(a, x) cerr<<#a<<"["<<x<<"] = "<<a[x]<<endl;
#define lson l,mid,ls
#define rson mid+1,r,rs
#define ls (rt<<1)
#define rs ((rt<<1)|1)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int loveisblue = 486;
const int maxn = 1689;
const int maxm = 100086;
const int inf = 0x3f3f3f3f;
const ll Inf = 999999999999999999;
const int mod = 1000000007;
const double eps = 1e-6;
const double pi = acos(-1); ll dp[maxn][maxn];
ll num[maxn][maxn];
ll sum[maxn];
int main() {
ios::sync_with_stdio(true);
#ifndef ONLINE_JUDGE
freopen("in.txt", "r", stdin);
#endif int n,m;
scanf("%d%d",&n,&m);
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
scanf("%lld",&num[i][j]);
}
}
ll ans = -Inf;
for(int i=1;i<=n;i++){
if(i&1){
ll mx = -Inf;
for(int j=1;j<=m;j++){
sum[j]=sum[j-1]+num[i][j]; dp[i][j]=mx+sum[j]; mx = max(mx,dp[i-1][j]);
} }else{
ll mx=-Inf;
for(int j=1;j<=m;j++){
sum[j]=sum[j-1]+num[i][j];
}
for(int j=m;j>=1;j--){
dp[i][j]=mx+sum[j];
mx = max(mx,dp[i-1][j]);
} }
}
for(int i=n;i<=n;i++){
for(int j=1;j<=m;j++){
ans=max(ans,dp[i][j]);
// cout<<dp[i][j]<< " ";
}
// cout<<endl; }
printf("%lld\n",ans); return 0;
}

Comb CodeForces - 46E (动态规划)的更多相关文章

  1. Codeforces 837D 动态规划

    Codeforces 837D 动态规划 传送门:https://codeforces.com/contest/837/problem/D 题意: 给你n个数,问你从这n个数中取出k个数,这k个数的乘 ...

  2. codeforces 1183H 动态规划

    codeforces 1183H 动态规划 传送门:https://codeforces.com/contest/1183/problem/H 题意: 给你一串长度为n的字符串,你需要寻找出他的最长的 ...

  3. Educational Codeforces Round 21 Problem E(Codeforces 808E) - 动态规划 - 贪心

    After several latest reforms many tourists are planning to visit Berland, and Berland people underst ...

  4. CODEFORCES 429B 动态规划

    http://codeforces.com/problemset/problem/429/B 可以参考这篇文章: http://blog.csdn.net/pure_lady/article/deta ...

  5. CodeForces 366C 动态规划 转化背包思想

    这道题目昨晚比赛没做出来,昨晚隐约觉得就是个动态规划,但是没想到怎么DP,今天想了一下,突然有个点子,即局部最优子结构为 1-j,j<i,遍历i,每次从所有的1到j当中的最优解里面与当前商品进行 ...

  6. Codeforces 607A 动态规划

    A. Chain Reaction time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...

  7. Codeforces Flipping game 动态规划基础

    题目链接:http://codeforces.com/problemset/problem/327/A 这道题目有O(N^3)的做法,这里转化为动态规划求解,复杂度是O(N) #include < ...

  8. 【动态规划】Codeforces 711C Coloring Trees

    题目链接: http://codeforces.com/problemset/problem/711/C 题目大意: 给N棵树,M种颜色,已经有颜色的不能涂色,没颜色为0,可以涂色,每棵树I涂成颜色J ...

  9. 【动态规划】【最短路】Codeforces 710E Generate a String

    题目链接: http://codeforces.com/problemset/problem/710/E 题目大意: 问写N个字符的最小花费,写一个字符或者删除一个字符花费A,将当前的字符数量翻倍花费 ...

随机推荐

  1. 远程安装App到手机

    注意: 必须是手机和电脑网络连通正常 1. 手机端安装终端模拟器. 2. 打开终端模拟器执行下面命令(也可以在adb shell中执行): su setprop service.adb.tcp.por ...

  2. bzoj1221 软件开发

    Description 某软件公司正在规划一项n天的软件开发计划,根据开发计划第i天需要ni个软件开发人员,为了提高软件开发人员的效率,公司给软件人员提供了很多的服务,其中一项服务就是要为每个开发人员 ...

  3. Java8 日期、时间操作

    一.简介 在Java8之前,日期时间API一直被开发者诟病,包括:java.util.Date是可变类型,SimpleDateFormat非线程安全等问题.故此,Java8引入了一套全新的日期时间处理 ...

  4. 使用 UIWebView 来播放视频

    MPMoviePlayerController 并不是继承自 UIViewController SDK 中的例子使用的是 addSubviews 的方式来添加 MPMoviePlayerControl ...

  5. php输入流简单小例子

    <form method="post" action="index.php/home/index/captchaTest"> <input n ...

  6. Java练习 SDUT-2728_最佳拟合直线

    最佳拟合直线 Time Limit: 1000 ms Memory Limit: 65536 KiB Problem Description 在很多情况下,天文观测得到的数据是一组包含很大数量的序列点 ...

  7. 【NS2】添加mUDP、mUdpSink和mTcpSink模块

    根据柯老师的教材可知,mUDP是UDP的延伸,除了具有UDP的功能外,还能记录所发送的包的信息.mUdpSink可以把接收到的包的信息记录 到文件中.mTcpSink是TCPsink的延伸,除了具有T ...

  8. Laravel 发送邮件(最简单的讲解!)

    Laravel集成了SwiftMailer库进行邮件发送,邮件配置文件位于config/mail.php:. return [ 'driver' => env('MAIL_DRIVER', 's ...

  9. rank(),允许并列名次、复制名次自动空缺,结果如12245558……

    将score按ID分组排名:rank() over(partition by id order by score desc) 将score不分组排名:rank() over(order by scor ...

  10. 伪元素 before 和 after 各种妙用

    大家可能对伪类和伪元素有点迷糊,在介绍具体用法之前,简单介绍下伪类和伪元素.伪类大家听的多了,伪元素可能听到的不是那么频繁,其实 CSS 对这两个是有区分的. 这里整理总结下: 有时你会发现伪类元素使 ...