题面

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. 洛谷 P1505 [国家集训队]旅游 树链剖分

    目录 题面 题目链接 题目描述 输入输出格式 输入格式 输出格式 输入输出样例 输入样例: 输出样例: 说明 思路 AC代码 总结 题面 题目链接 P1505 [国家集训队]旅游 题目描述 Ray 乐 ...

  2. C++简单读取 & 写入实例

    #include <fstream> #include <iostream> using namespace std; int main () { ]; // 以写模式打开文件 ...

  3. 洛谷P2522 [HAOI2011]Problem b (莫比乌斯反演+容斥)

    题意:求$\sum_{i=a}^{b}\sum_{j=c}^{d}[gcd(i,j)==k]$(1<=a,b,c,d,k<=50000). 是洛谷P3455 [POI2007]ZAP-Qu ...

  4. Python中并发前戏之操作系统

    进程: 1.串行: 一个任务完完整整地运行完毕后,才能运行下一个任务 2.并发 看起来多个任务是同时运行的即可,单核也可以实现并发 3.并行: 真正意义上多个任务的同时运行,只有多核才实现并行 1.什 ...

  5. C# 从零开始写 SharpDx 应用 初始化dx修改颜色

    原文:C# 从零开始写 SharpDx 应用 初始化dx修改颜色 版权声明:博客已迁移到 https://blog.lindexi.com 欢迎访问.如果当前博客图片看不到,请到 https://bl ...

  6. 洛谷 3174 [HAOI2009]毛毛虫

    题目描述 对于一棵树,我们可以将某条链和与该链相连的边抽出来,看上去就象成一个毛毛虫,点数越多,毛毛虫就越大.例如下图左边的树(图 1 )抽出一部分就变成了右边的一个毛毛虫了(图 2 ). 输入输出格 ...

  7. 洛谷P1653 猴子

    #include<bits/stdc++.h> using namespace std; inline void read(int &tmp) { ;char c=getchar( ...

  8. 9 模版语言 jinja2

    from flask import Flask,redirect,render_template,jsonify,send_file,request,Markup,sessionimport json ...

  9. 5 获取Form表单取值

    #form表达提交@app.route("/data",methods=['GET','POST']) #methods 让当前路由支持GET 和 POST 方式def data( ...

  10. E - D Tree HDU - 4812 点分治+逆元

    这道题非常巧妙!!! 我们进行点分治的时候,算出当前子节点的所有子树中的节点,到当前节点节点的儿子节点的距离,如下图意思就是 当前节点的红色节点,我们要求出红色节点的儿子节点绿色节点,所有绿色的子树节 ...