codeforce Gym 100500H ICPC Quest (简单dp)
题意:给一个nXm的矩阵,上面有一些数字,从左上角出发,每次只能往右或者往下,把沿途的数字加起来,求到达右下角的最大值是多少。
题解:简单的一个dp,设f[i][j]为到达i行j列的最大值,f[i][j] = max(f[i-1][j],f[i][j-1])+a[i][j],然后用队列刷表法。
#include<cstdio>
#include<cstring>
#include<queue>
using namespace std;
typedef long long ll;
//#define local
#define fi first
#define se second
const int maxn = ; int f[maxn][maxn];
int a[maxn][maxn];
int main()
{
int T;
scanf("%d",&T);
for(int k = ; k <= T; k++) {
int n,m;
scanf("%d%d",&n,&m);
for(int i = ; i < n; i++){
for(int j = ; j < m; j++){
scanf("%d",a[i]+j);
}
}
queue< pair<int,int> > q;
memset(f,0x80,sizeof(f));
q.push(make_pair(,));
f[][] = a[][];
while(q.size()){
pair<int,int> &u = q.front();
int r = u.fi, c = u.se;
if(r<n && f[r+][c]<f[r][c]+a[r+][c]) f[r+][c] = f[r][c]+a[r+][c],q.push(make_pair(r+,c));
if(c<m && f[r][c+]<f[r][c]+a[r][c+]) f[r][c+] = f[r][c]+a[r][c+],q.push(make_pair(r,c+));
q.pop();
}
printf("Case %d: %d\n",k,f[n-][m-]);
}
return ;
}
codeforce Gym 100500H ICPC Quest (简单dp)的更多相关文章
- codeforce Gym 100500C ICPC Giveaways(水)
读懂题意就是水题,按照出现次数对下标排一下序,暴力.. #include<cstdio> #include<algorithm> #include<cstring> ...
- codeforces Gym 100500H A. Potion of Immortality 简单DP
Problem H. ICPC QuestTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100500/a ...
- codeforces Gym 100500H H. ICPC Quest 水题
Problem H. ICPC QuestTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100500/a ...
- HDU 1087 简单dp,求递增子序列使和最大
Super Jumping! Jumping! Jumping! Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 ...
- Codeforces Round #260 (Div. 1) A. Boredom (简单dp)
题目链接:http://codeforces.com/problemset/problem/455/A 给你n个数,要是其中取一个大小为x的数,那x+1和x-1都不能取了,问你最后取完最大的和是多少. ...
- 简单dp --- HDU1248寒冰王座
题目链接 这道题也是简单dp里面的一种经典类型,递推式就是dp[i] = min(dp[i-150], dp[i-200], dp[i-350]) 代码如下: #include<iostream ...
- poj2385 简单DP
J - 简单dp Crawling in process... Crawling failed Time Limit:1000MS Memory Limit:65536KB 64bit ...
- hdu1087 简单DP
I - 简单dp 例题扩展 Crawling in process... Crawling failed Time Limit:1000MS Memory Limit:32768KB ...
- poj 1157 LITTLE SHOP_简单dp
题意:给你n种花,m个盆,花盆是有顺序的,每种花只能插一个花盘i,下一种花的只能插i<j的花盘,现在给出价值,求最大价值 简单dp #include <iostream> #incl ...
随机推荐
- HDU - 1535 Invitation Cards 前向星SPFA
Invitation Cards In the age of television, not many people attend theater performances. Antique Come ...
- Litjson
http://www.cnblogs.com/peiandsky/archive/2012/04/20/2459219.html JSON(JavaScript Object Notation) 是一 ...
- 51nod1412(dp)
题目链接:https://www.51nod.com/onlineJudge/questionCode.html#!problemId=1412 代码: #include <bits/stdc+ ...
- Google Analytics & Webtrend 使用笔记
GA和webtrend中的参数,每每遇到了都记不住.遇到一点记一点好了... Page Views(PV): 浏览次数.用户每打开一个页面,记录为1个PV:用户多次打开同一个页面,PV累计多次. Da ...
- Etherscan API 中文文档-账号
本文原文链接 点击这里获取Etherscan API 中文文档(完整版) 完整内容排版更好,推荐读者前往阅读. 账号(Account) 账号及地址相关的 API,接口的参数说明请参考Etherscan ...
- Jenkins+Git+Docker+K8s部署
准备工作 Jenkins已安装 Docker和K8s部署运行成功 代码管理工具使用Git 最近公司项目使用Jenkins+Git+Docker+K8s进行持续化构建部署,这里笔者整理了一下构建部署的相 ...
- git 的基本设置以及使用
https://www.linuxidc.com/Linux/2018-05/152611.htm 详解git add , git commit , git push, 等命令 https://blo ...
- [題解](水/數學)luogu_P1147連續自然數和
尺取法a掉 然而數學解法為 等差數列求和公式: sum(L,R)=(L+R)(R-L+1)/2=M 即(L+R)(R-L+1)=2M 可以把2M分解成两个数之积,假设分成了两个数K1,K2,且K1&l ...
- openSUSE 跨版本升级
准备工作 此方法通过网络跨版本升级,适合 Leap 升级到下一个发行版(如 42.2 升级到 42.3),也适合 Leap 升级为 Tumbleweed.首先必须确定升级的时候有足够的时间.靠谱的更新 ...
- SQLServer数据库表字段超长,找到超长字段脚本
平时开发系统时偶尔会遇到数据超长导致往数据库中保存时出错. 使用下边的脚本可以方便的找出超长的字段. 1.通过正式表创建临时表,修改临时表中varchar.nvarchar的长度为max ); ); ...