hdu 1078 FatMouse and Cheese
来源:互联网 发布:修改pdf文件的软件 编辑:程序博客网 时间:2024/05/21 22:56
http://acm.hdu.edu.cn/showproblem.php?pid=1078
哈哈 记忆化搜索 第一次自己写的过了
努力终于有回报了啊^-^
代码:
#include <stdio.h>#include <stdlib.h>#include <math.h>#include <string.h>#include <iostream>#include <algorithm>#include <map>#include <set>#include <queue>using namespace std;int grid[105][105];int maps[105][105];int dx[]={1,-1,0,0};int dy[]={0,0,-1,1}; int n,k;int check(int x,int y){ if(x<1||y<1||x>n||y>n) return 0; return 1;}int search(int x,int y){ //printf("~%d %d\n",x,y); if(!check(x,y)) return 0; if(maps[x][y]!=0) return maps[x][y]; for(int i=1;i<=k;i++) for(int j=0;j<=3;j++) { if(grid[(x+dx[j]*i)][(y+dy[j]*i)]>grid[x][y]) maps[x][y]=max(maps[x][y],grid[x][y]+search(x+dx[j]*i,y+dy[j]*i)); if(maps[x][y]==0) maps[x][y]=grid[x][y]; } return maps[x][y];}int main(){ while(scanf("%d%d",&n,&k),n!=-1||k!=-1) { memset(maps,0,sizeof(maps)); for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) scanf("%d",&grid[i][j]); printf("%d\n",search(1,1)); }}
- 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
- Android中Intent传递对象的两种方法(Serializable,Parcelable)
- @@count=0 @name ="Jim"
- DirectUI之CMenu(支持透明、异形)
- 安装WPS for Linux Alpha 6后Ubuntu字体渲染出现问题的解决方案
- 实现Android计时与倒计时方法
- hdu 1078 FatMouse and Cheese
- 我曾经也是个程序员
- 手机Camera相关介绍
- def StudentClass.student_count
- 从1 到n 的正数中1 出现的次数
- 维基百科,希尔排序
- 微软等数据结构+算法面试100题(1)--用到的数据结构和函数
- Java中整数(秒数)转换为时分秒格式(xx:xx:xx)
- C++第11周项目3(1)——判断素数