[HDU] 2391 Filthy Rich 入门dp
2013-04-22 13:44
423 查看
题目链接:
http://acm.hdu.edu.cn/showproblem.php?pid=2391
方法:建立状态转移方程,设F(x,y)为走到x,y点已经获得了的最大黄金数量,curent(x,y)为该点本身具有的黄金数量,则
{
0 , x<1|| y<1;
F(x,y)= Max(F(x-1,y)+current(x,y), F(x,y-1)+current(x,y),F(x-1,y-1)+current(x,y));//因为每一个位置最多可以从3个方向到达。
current(1,1) , x==1 && y==1;
}
感想:适合dp入门练习。
代码:
View Code
http://acm.hdu.edu.cn/showproblem.php?pid=2391
方法:建立状态转移方程,设F(x,y)为走到x,y点已经获得了的最大黄金数量,curent(x,y)为该点本身具有的黄金数量,则
{
0 , x<1|| y<1;
F(x,y)= Max(F(x-1,y)+current(x,y), F(x,y-1)+current(x,y),F(x-1,y-1)+current(x,y));//因为每一个位置最多可以从3个方向到达。
current(1,1) , x==1 && y==1;
}
感想:适合dp入门练习。
代码:
View Code
#include<iostream> using namespace std; int MyMax(int x,int y, int z) { if(x>=y) { if(y>=z) return x; if(z>=x) return z; return x; } if(y<=z) return z; return y; } int dp[1001][1001]; int main() { int tc=0,t; scanf("%d",&t); int a,b; while(tc<t) { memset(dp,0,sizeof(dp)); scanf("%d %d",&a,&b); for(int i =1;i<=a;i++) for(int j =1;j<=b;j++) scanf("%d",&dp[i][j]); for(int i =1;i<=a;i++) for(int j =1;j<=b;j++) dp[i][j] = MyMax(dp[i][j]+dp[i-1][j],dp[i][j]+dp[i][j-1],dp[i][j]+dp[i-1][j-1]); cout<<"Scenario #"<<tc+1<<":"<<endl<<dp[a][b]<<endl<<endl; tc++; } return 0; }
相关文章推荐
- HDU 2391 Filthy Rich
- HDU 2391--Filthy Rich【数塔】
- HDOJ 题目2391Filthy Rich(水dp)
- HDoj2391-Filthy Rich-DP
- hdu 2391 filthy rich
- hdoj 2391 Filthy Rich 【DP】
- HDU 2391 Filthy Rich
- [HDU] 4405 Aeroplane chess 期望dp入门
- [HDU] 3853 LOOPS 期望dp入门
- hdu 2993 MAX Average Problem(斜率DP入门题)
- Hdu 2089 不要62(数位dp入门)
- hdu 2089 不要62(数位dp入门)
- hdu_Anniversary party_(树形DP入门题)
- hdu 5379 Mahjong tree 树形DP入门
- HDU 2089 不要62(数位DP入门+模板)
- hdu 2993 MAX Average Problem(DP+斜率优化入门题)
- DP入门,HDU 2084 数塔 参考代码
- Hdu 3507 Print Article【斜率优化Dp入门】
- HDU 3853 LOOPS 概率dp入门 (1)
- HDU 2391 Filthy Rich(dp)