hdu1078
#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;
int n,k,dp[105][105],a[105][105];
int to[4][2] = {1,0,-1,0,0,1,0,-1};
int check(int x,int y)
{
if(x<1 || y<1 || x>n || y>n)
return 1;
return 0;
}
int dfs(int x,int y)
{
int i,j,l,ans = 0;
if(!dp[x][y])
{
for(i = 1; i<=k; i++)
{
for(j = 0; j<4; j++)
{
int xx = x+to[j][0]*i;
int yy = y+to[j][1]*i;
if(check(xx,yy))
continue;
if(a[xx][yy]>a[x][y])
ans = max(ans,dfs(xx,yy));
}
}
dp[x][y] = ans+a[x][y];
}
return dp[x][y];
}
int main()
{
int i,j;
while(~scanf("%d%d",&n,&k),n>0&&k>0)
{
for(i = 1; i<=n; i++)
for(j = 1; j<=n; j++)
scanf("%d",&a[i][j]);
memset(dp,0,sizeof(dp));
printf("%d\n",dfs(1,1));
}
return 0;
}
最新文章
- 用C表达面向对象语言的机制——C#版
- 使用h5的history改善ajax列表请求体验
- django model Meta选项
- 配置文件操作模块,configparser
- mysql登陆出现unknown database错误可能原因
- MyBatis知多少(25)动态SQL
- js——全选框 checkbox
- Hadoop系统架构
- Dell™ SAS 5/iR 集成适配器和适配器用户指南
- ExtJs store加载
- java学习之常量与进制
- jquery mobile 按钮部件(包含图标的使用)
- 移动平台Unity3D 应用性能优化
- Win10图片打开方式没有“Windows照片查看器”,如何找回?
- 小程序for循环中通过index实现单个点击事件
- Webapck项目开发基本构建及配置
- truffle init 从零开始创建简单DApp项目
- js基础梳理-关于this常见指向问题的分析
- [c/c++] programming之路(20)、字符串(一)
- 安装 composer 并启动 yii2 项目
热门文章
- Android蓝牙开发浅析【转】
- runtime 实现方法交换 viewwillappear方法
- 算法(Algorithms)第4版 练习 1.5.8
- MySQL部署时Table &#39;mysql.plugin&#39; doesn&#39;t exist的解决
- Windows下控制Nginx的状态
- 初步认识Express框架渲染视图
- 恢复delete删除的数据
- 10 Python 数据类型—集合
- PHP获取当前日期及本周一是几月几号的方法
- codeforces 515C C. Drazil and Factorial(水题,贪心)