#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;
}

最新文章

  1. 用C表达面向对象语言的机制——C#版
  2. 使用h5的history改善ajax列表请求体验
  3. django model Meta选项
  4. 配置文件操作模块,configparser
  5. mysql登陆出现unknown database错误可能原因
  6. MyBatis知多少(25)动态SQL
  7. js——全选框 checkbox
  8. Hadoop系统架构
  9. Dell™ SAS 5/iR 集成适配器和适配器用户指南
  10. ExtJs store加载
  11. java学习之常量与进制
  12. jquery mobile 按钮部件(包含图标的使用)
  13. 移动平台Unity3D 应用性能优化
  14. Win10图片打开方式没有“Windows照片查看器”,如何找回?
  15. 小程序for循环中通过index实现单个点击事件
  16. Webapck项目开发基本构建及配置
  17. truffle init 从零开始创建简单DApp项目
  18. js基础梳理-关于this常见指向问题的分析
  19. [c/c++] programming之路(20)、字符串(一)
  20. 安装 composer 并启动 yii2 项目

热门文章

  1. Android蓝牙开发浅析【转】
  2. runtime 实现方法交换 viewwillappear方法
  3. 算法(Algorithms)第4版 练习 1.5.8
  4. MySQL部署时Table &#39;mysql.plugin&#39; doesn&#39;t exist的解决
  5. Windows下控制Nginx的状态
  6. 初步认识Express框架渲染视图
  7. 恢复delete删除的数据
  8. 10 Python 数据类型—集合
  9. PHP获取当前日期及本周一是几月几号的方法
  10. codeforces 515C C. Drazil and Factorial(水题,贪心)