HDU 1078 FatMouse and Cheese
来源:互联网 发布:淘宝达人账号如何注销 编辑:程序博客网 时间:2024/05/24 02:08
/*记忆化搜索P - FatMouse and Cheese题意: 从(0,0)出发,每次最多走k格,但每次只能往值比它现在在的值大的格子走。题解:dp[i][j] 代表走到(i,j)的最大总值。dp[i][j] = max(dp[prei][prej]+mp[i][j]){i,j 是 prei,prej能走到的格子}贡献1T,1Wa,注意题意走K步是只能笔直走K步,导致T。我以为我nextx是不断更新的,没乘j,导致wa。*/#include<cstdio>#include<cstring>#include<cmath>#include<iostream>#include<algorithm>#include<queue>#include<stack>#include<map>using namespace std;const int N = 110;int n,k;int dx[5] = {0,0,1,-1};int dy[5] = {1,-1,0,0};int mp[N][N],v[N][N];int dp[N][N];bool pan(int i,int j){ if(i >= 0 && i < n && j >= 0 && j < n) return true; return false;}int DFS(int x,int y){ int &ans = dp[x][y]; if(v[x][y]) return ans; ans = mp[x][y]; v[x][y] = 1; for(int i = 0; i < 4; i++) { for(int j = 1; j <= k; j++) { int nextx = x+dx[i]*j,nexty = y+dy[i]*j; if(pan(nextx,nexty) && mp[x][y] < mp[nextx][nexty]) ans = max(ans,DFS(nextx,nexty)+mp[x][y]); } } return ans;}int main(){ while(cin >> n >> k) { if(n == -1 && k == -1) break; memset(dp,0,sizeof(dp)); memset(mp,0,sizeof(mp)); memset(v,0,sizeof(v)); for(int i = 0; i < n; i++) for(int j = 0; j < n; j++) scanf("%d",&mp[i][j]); int ans = DFS(0,0); cout << ans << endl; } return 0;}
0 0
- HDU 1078 FatMouse and Cheese
- hdu 1078 FatMouse and Cheese
- hdu 1078 FatMouse and Cheese
- hdu 1078 FatMouse and Cheese
- hdu 1078 FatMouse and Cheese
- hdu-1078-FatMouse and Cheese
- HDU 1078 FatMouse and Cheese
- HDU 1078 FatMouse and Cheese
- Hdu 1078 FatMouse and Cheese
- HDU 1078 FatMouse and Cheese
- HDU 1078 FatMouse and Cheese
- hdu 1078 FatMouse and Cheese
- HDU 1078 FatMouse and Cheese
- HDU 1078 FatMouse and Cheese
- hdu 1078 FatMouse and Cheese
- HDU 1078 FatMouse and Cheese
- HDU 1078 FatMouse and Cheese
- HDU 1078 FatMouse and Cheese
- 利用springboot对oracle中数据库表的增删改查crud
- 【mysql】mac终端下启动和停止mysql服务
- Linux下安装TFTP服务的具体操作
- C# 发起普通http请求
- iOS多个网络请求问题
- HDU 1078 FatMouse and Cheese
- #!/usr/bin/env python的作用
- Spring源码学习之AOP
- 运维笔记31 (pacemaker高可用集群搭建的总结)
- LeetCode-496. Next Greater Element I
- Android Material Design -TextInputLayout
- 公众号第三方平台和微信公众号平台的区别与开发步骤
- 程序中乱码解决方案
- 集合各实现类的底层实现原理