Comb CodeForces - 46E (动态规划)
题面
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 (动态规划)的更多相关文章
- Codeforces 837D 动态规划
Codeforces 837D 动态规划 传送门:https://codeforces.com/contest/837/problem/D 题意: 给你n个数,问你从这n个数中取出k个数,这k个数的乘 ...
- codeforces 1183H 动态规划
codeforces 1183H 动态规划 传送门:https://codeforces.com/contest/1183/problem/H 题意: 给你一串长度为n的字符串,你需要寻找出他的最长的 ...
- Educational Codeforces Round 21 Problem E(Codeforces 808E) - 动态规划 - 贪心
After several latest reforms many tourists are planning to visit Berland, and Berland people underst ...
- CODEFORCES 429B 动态规划
http://codeforces.com/problemset/problem/429/B 可以参考这篇文章: http://blog.csdn.net/pure_lady/article/deta ...
- CodeForces 366C 动态规划 转化背包思想
这道题目昨晚比赛没做出来,昨晚隐约觉得就是个动态规划,但是没想到怎么DP,今天想了一下,突然有个点子,即局部最优子结构为 1-j,j<i,遍历i,每次从所有的1到j当中的最优解里面与当前商品进行 ...
- Codeforces 607A 动态规划
A. Chain Reaction time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...
- Codeforces Flipping game 动态规划基础
题目链接:http://codeforces.com/problemset/problem/327/A 这道题目有O(N^3)的做法,这里转化为动态规划求解,复杂度是O(N) #include < ...
- 【动态规划】Codeforces 711C Coloring Trees
题目链接: http://codeforces.com/problemset/problem/711/C 题目大意: 给N棵树,M种颜色,已经有颜色的不能涂色,没颜色为0,可以涂色,每棵树I涂成颜色J ...
- 【动态规划】【最短路】Codeforces 710E Generate a String
题目链接: http://codeforces.com/problemset/problem/710/E 题目大意: 问写N个字符的最小花费,写一个字符或者删除一个字符花费A,将当前的字符数量翻倍花费 ...
随机推荐
- 为什么要Code Review
刚才专注看了下zwchen的博客,读到Code Reivew这一篇,觉得自己也了说话的冲动. 我们Team实施Code Reivew近5年,到今天,我们的结论是: Code Review是我们项目成功 ...
- zend studio打开文件提示unsupported character encoding
zend studio打开文件提示unsupported character encoding,是文件的编码方式错误. 有可能是PHP代码中,charset={CHARSET} ,用了变量的形式调用编 ...
- 2015全球商业地产商影响力排行TOP10:中国占据5个
2015全球商业地产商影响力排行TOP10:中国占据5个 1.西蒙丨依然最有影响力 发展概况:西蒙公司是北美商业地产(专题阅读)的王者,美最大商业地产REITS,1960年最初只以开发为主,1993年 ...
- C++运行时类型识别
通过运行时类型识别(RTTI),程序能够使用基类的指针或引用来检索这些指针或引用所指对象的实际派生类型. 通过下面两个操作符提供 RTTI: 1. typeid 操作符,返回指针或引用所指对象的实际类 ...
- oralce ROLLUP
select id,area,stu_type,sum(score) score from students group by rollup(id,area,stu_type) order by id ...
- Go 语言开发工具
Go 语言开发工具 LiteIDE LiteIDE是一款开源.跨平台的轻量级Go语言集成开发环境(IDE). 支持的操作系统 Windows x86 (32-bit or 64-bit) Linux ...
- 神经网络为什么需要多次epoch
Δw(t)=−ε ∂w(t)∂E +αΔw(t−1)(9) 我们知道反向传播每次迭代的效果是这样的:w=w+Δw(t) w=w+\Delta w(t)w=w+Δw(t) 我们知道,每条训练数据都会导 ...
- html前端登录验证
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- uva 12296 Pieces and Discs (Geometry)
http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&p ...
- SuperSocket AppServer 的两个事件: NewSessionConnected 和 SessionClosed
订阅事件: appServer.NewSessionConnected += new SessionHandler<AppSession>(appServer_NewSessionConn ...