HDU 1078 FatMouse and Cheese (记忆化dp)
来源:互联网 发布:linux 守护进程 服务器 编辑:程序博客网 时间:2024/06/04 01:29
思路:
- 注意读题:每次胖老鼠跑路都只能上下左右的跑一条直线。
- 由于只能由小的走向大的,所以我们可以逆向递推。就跟松塔一样。
#include <iostream>#include <cstdio>#include <string.h>#include <algorithm>typedef long long int lli;using namespace std;int ma[120][120];lli dp[120][120];int n,kk;lli dfs(int i,int j){ lli ans = 0; for(int x=-kk;x <= kk;x++){ if(i+x < 1 || i+x > n) continue; if(ma[i+x][j] > ma[i][j]) ans = max(ans,dp[i+x][j]); } for(int x=-kk;x <= kk;x++){ if(j+x < 1 || j+x > n) continue; if(ma[i][j+x] > ma[i][j]) ans = max(ans,dp[i][j+x]); } dp[i][j] = ma[i][j] + ans; return dp[i][j];}struct node{ int i,j,v;}a[10100];int cnte;bool cmp(const node &a,const node &b){ return a.v > b.v;}int main(){ while(~scanf("%d%d",&n,&kk),n!=-1&&kk!=-1){ memset(dp,0,sizeof(dp));cnte = 0; for(int i = 1;i <= n;i++){ for(int j = 1;j <= n;j++){ scanf("%d",&ma[i][j]); a[++cnte].i=i;a[cnte].j=j;a[cnte].v=ma[i][j]; } } int mm = n*n;lli ans = 0; sort(a+1,a+1+mm,cmp); for(int i = 1;i <= mm;i++){ ans = max(ans,dfs(a[i].i,a[i].j)); if(a[i].i == 1 && a[i].j==1) break; } printf("%lld\n",dp[1][1]); } return 0;}
阅读全文
1 0
- hdu(1078) FatMouse and Cheese (记忆化搜索+dp)
- !HDU 1078 FatMouse and Cheese-dp-(记忆化搜索)
- HDU 1078 FatMouse and Cheese (记忆化dp)
- hdu 1078 FatMouse and Cheese(dp 记忆化搜索)
- hdu 1078 FatMouse and Cheese 记忆化dp
- HDU 1078 FatMouse and Cheese 简单DP&记忆化搜索
- HDU 1078 FatMouse and Cheese 记忆化搜索模板 dp
- [HDU 1078 ] FatMouse and Cheese [ dp 记忆化搜索 ]
- HDU FatMouse and Cheese (记忆化搜索+dp思想)
- hdu-1078 FatMouse and Cheese (and) 滑雪问题(记忆化搜索+简单dp)
- hdu-1078 FatMouse and Cheese (and) 滑雪问题(记忆化搜索+简单dp)
- FatMouse and Cheese(HDU 1078) —— 记忆化搜索DP
- HDU 1078 FatMouse and Cheese(记忆化搜索 Or DP)
- HDU 1078 FatMouse and Cheese (dfs + dp记忆化搜索)
- hdu 1078 FatMouse and Cheese(深搜----记忆化搜索)
- hdu 1078 FatMouse and Cheese (记忆化搜索 )
- hdu 1078 FatMouse and Cheese(记忆化搜索)
- HDU 1078 FatMouse and Cheese(记忆化搜索)
- 模板:并查集
- 关于深浅拷贝
- 从输入url到显示页面发生了什么
- 浏览器缓存
- 网络编程之java.net.SocketException: Connection reset异常问题
- HDU 1078 FatMouse and Cheese (记忆化dp)
- AJAX初学者简单小示例
- C++中的动态内存管理
- maven安装与使用 Linux
- Android-自定义能力分布图
- JSP 摘记
- scikit-learn 朴素贝叶斯类库使用小结
- CI文件上传失败原因
- iOS上LaunchImage(启动页) 在模拟器上显示真机不显示