HDU 1078 FatMouse and Cheese(简单DP)
来源:互联网 发布:数据加密的目的是 编辑:程序博客网 时间:2024/06/06 02:21
解题思路:
很水的DP,记得按照权值大小排序即可。
#include <iostream>#include <cstring>#include <cstdlib>#include <cstdio>#include <algorithm>#include <cmath>#include <vector>#include <queue>#include <stack>#include <set>#include <map>#define LL long long#define FOR(i,x,y) for(int i=x;i<=y;i++)using namespace std;const int maxn = 100 + 10;struct Node{ int x; int y; int w; bool operator < (const Node &rhs)const { return w < rhs.w; }}nodes[maxn*maxn];int W[maxn][maxn];int dp[maxn][maxn];int N, K, M;int main(){ while(scanf("%d%d", &N,&K)!=EOF) { if(N == -1 && K == -1) break; M = 0; FOR(i,1,N) { FOR(j,1,N) { scanf("%d", &W[i][j]); nodes[++M].x = i; nodes[M].y = j; nodes[M].w = W[i][j]; } } memset(dp,-1,sizeof(dp)); dp[1][1] = W[1][1]; int ans = -1; sort(nodes+1, nodes+1+M); FOR(i,1,M) { int x = nodes[i].x; int y = nodes[i].y; for(int xx=max(1,x-K);xx<=min(N,x+K);xx++) { if(W[x][y] > W[xx][y] && dp[xx][y] != -1) { dp[x][y] = max(dp[x][y], dp[xx][y] + W[x][y]); } } for(int yy=max(1,y-K);yy<=min(N,y+K);yy++) { if(W[x][y] > W[x][yy] && dp[x][yy] != -1) { dp[x][y] = max(dp[x][y], dp[x][yy] + W[x][y]); } } ans = max(ans , dp[x][y]); } printf("%d\n", ans); } return 0;}
0 0
- HDU 1078 FatMouse and Cheese(简单DP)
- HDU 1078 FatMouse and Cheese 简单DP&记忆化搜索
- hdu-1078 FatMouse and Cheese (and) 滑雪问题(记忆化搜索+简单dp)
- hdu-1078 FatMouse and Cheese (and) 滑雪问题(记忆化搜索+简单dp)
- hdu 1078 FatMouse and Cheese (搜索+dp)
- hdu 1078(dfs+dp)FatMouse and Cheese
- HDU 1078 FatMouse and Cheese(DP)
- HDU 1078 FatMouse and Cheese(DP)
- HDU 1078 FatMouse and Cheese(经典DP)
- hdu 1078 FatMouse and Cheese【dp】
- DP-HDU-1078-FatMouse and Cheese
- HDU - 1078----FatMouse and Cheese(dp制表)
- hdu 1078 FatMouse and Cheese【dfs+dp】
- hdu 1078 FatMouse and Cheese (dp+dfs)
- hdu FatMouse and Cheese(dp)
- hdu(1078) FatMouse and Cheese (记忆化搜索+dp)
- !HDU 1078 FatMouse and Cheese-dp-(记忆化搜索)
- HDU 1078 FatMouse and Cheese (记忆化dp)
- F2FS – A New Flash File System for Mobile Devices – ELCE 2012
- 嵌入式Linux工程师自学笔记
- project euler 18/67
- 社説 20150131 国内生産回帰 事業環境の改善を急ぎたい
- 分享:SQL Server注入检测函数
- HDU 1078 FatMouse and Cheese(简单DP)
- 我的学习之旅(43)asm.s
- Linux初学者的学习指导
- RDIFramework.NET ━ 9.4 角色管理 ━ Web部分
- STDIN_FILENO的作用及与stdin 的区别
- django下载文件处理
- CKEditor&ckfindtor
- Objective-C 学习笔记 09 - 第一个iOS应用程序
- 20个开源项目托管站点推荐