Poj2948Martian Mining(记忆化)
这题意好难懂 看得迷迷糊糊 想的也迷迷糊糊 后来睡了会突然想到了。。不就是类似以前的矩阵操作
从右下角记忆化 大的由小的推来
dp[i][j] = max(dp[i-1][j]+s1,dp[i][j-1]+s2) s1 = a[i][g]+..a[i][j] s2 = b[g][j]+..b[i][j]
#include <iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<stdlib.h>
using namespace std;
int dp[][];
int n,m;
int a[][];
int b[][];
int dfs(int i,int j)
{
if(i<||j<)
return ;
if(dp[i][j]!=-)
return dp[i][j];
int g,s1=,s2=;
for(g = ; g <= i ; g++)
s1+=b[g][j];
for(g = ; g <= j ; g++)
s2+=a[i][g];
dp[i][j] = max(dfs(i-,j)+s2,dfs(i,j-)+s1);
return dp[i][j];
}
int main()
{
int i,j;
while(scanf("%d%d",&n,&m)!=EOF)
{
if(n==&&m==)
break;
memset(dp,-,sizeof(dp));
for(i = ; i <= n ; i++)
for(j = ; j <= m ; j++)
scanf("%d",&a[i][j]);
for(i = ; i <= n ; i++)
for(j = ; j <= m ; j++)
scanf("%d",&b[i][j]);
int ans = dfs(n,m);
printf("%d\n",ans);
}
return ;
}
Poj2948Martian Mining(记忆化)的更多相关文章
- *HDU1142 最短路+记忆化dfs
A Walk Through the Forest Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Jav ...
- [ACM_动态规划] 数字三角形(数塔)_递推_记忆化搜索
1.直接用递归函数计算状态转移方程,效率十分低下,可以考虑用递推方法,其实就是“正着推导,逆着计算” #include<iostream> #include<algorithm> ...
- 【BZOJ-3895】取石子 记忆化搜索 + 博弈
3895: 取石子 Time Limit: 1 Sec Memory Limit: 512 MBSubmit: 263 Solved: 127[Submit][Status][Discuss] D ...
- hdu3555 Bomb (记忆化搜索 数位DP)
http://acm.hdu.edu.cn/showproblem.php?pid=3555 Bomb Time Limit: 2000/1000 MS (Java/Others) Memory ...
- Codeforces Round #174 (Div. 1) B. Cow Program(dp + 记忆化)
题目链接:http://codeforces.com/contest/283/problem/B 思路: dp[now][flag]表示现在在位置now,flag表示是接下来要做的步骤,然后根据题意记 ...
- hdu 4826(dp + 记忆化搜索)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4826 思路:dp[x][y][d]表示从方向到达点(x,y)所能得到的最大值,然后就是记忆化了. #i ...
- zoj 3644(dp + 记忆化搜索)
题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=4834 思路:dp[i][j]表示当前节点在i,分数为j的路径条数,从 ...
- loj 1044(dp+记忆化搜索)
题目链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=26764 思路:dp[pos]表示0-pos这段字符串最少分割的回文 ...
- DP(记忆化搜索) + AC自动机 LA 4126 Password Suspects
题目传送门 题意:训练指南P250 分析:DFS记忆化搜索,范围或者说是图是已知的字串构成的自动机图,那么用 | (1 << i)表示包含第i个字串,如果长度为len,且st == (1 ...
随机推荐
- nginx-url重写
location /game_web{ if (!-e $request_filename){//请求不是文件或者目录 rewrite ^/game_web/(\/init/$ last; break ...
- php curl基本操作
如何使用cURL的基本方法?首先,修改php.ini文件的设置,找到php_curl.dll,取消下在的注释extension=php_curl.dll,因为php默认是不开启cURL的. cURL是 ...
- 装tortoiseSVN时遇到的坑
今天给新电脑配置开发环境,线上SVN地址申请权限以后,在本地装了tortoiseSVN,可是安装了以后死活打不开.明明浏览器里可以打开SVN地址,但是tortoiseSVN的浏览器里却打不开,摆弄了很 ...
- Delphi代码优化
文章编目 1. 字符串优化 1.1. 不重复初始化 1.2. 使用SetLength预分配长字符串(AnsiString) 1.3. 字符串与动态数组的线程安全(Thread Safety) 1.4. ...
- 《Visual C++ 程序设计》读书笔记 ----第8章 指针和引用
1.&取地址:*取内容. 2.指针变量“++”“--”,并不是指针变量的值加1或减1,而是使指针变量指向下一个或者上一个元素. 3.指针运算符*与&的优先级相同,左结合:++,--,* ...
- The Black Hole of Numbers (strtoint+inttostr+sort)
For any 4-digit integer except the ones with all the digits being the same, if we sort the digits in ...
- Java 多线程 简单实例 (Runnable)
1.多线程实例 package second; public class A implements Runnable { public char stat = '*'; public void run ...
- MyEclipse中文注释乱码解决
MyEclipse中文注释乱码解决 将别人的项目或JAVA文件导入到自己的Eclipse中时,常常会出现JAVA文件的中文注释变成乱码的情况,主要原因就是别人的IDE编码格式和自己的Eclipse编码 ...
- springMVC+MyBatis+Spring 整合(2)
mybatis 与Spring 的整合. 1.导入Spring 和Springmvc的包 pom <project xmlns="http://maven.apache.org/POM ...
- WCF 绑定的选择
选自<WCF服务编程中文版> 第一章 WCF基础 绑定服务之间的通信方式是多种多样的,有多种可能的通信模式.包括:同步的请求/ 应答(Request/Reply)消息,或者异步的“即发即弃 ...