LightOJ1004
#include<bits/stdc++.h>
using namespace std;
int Map[106][106];
int Vis[106][106];
int Num[106][106];
int T;
const int step[2][2] = {1,0,0,1}; void Init()
{
memset(Map,0,sizeof(Map));
memset(Vis,0,sizeof(Vis));
memset(Num,0,sizeof(Num));
} struct Node {
int x, y;
Node(int _x = 0, int _y = 0) :\
x(_x), y(_y) {}
}; int BFS(int n)
{
Num[0][0] = Map[0][0];
Node Begin(0,0);
queue<Node> Q;
Q.push(Begin);
while(!Q.empty())
{
Node c = Q.front();
Q.pop();
int s = Num[c.x][c.y];
for(int i = 0; i < 2; ++i)
{
int xx = c.x + step[i][0];
int yy = c.y + step[i][1];
//cout << Num[xx] << " " << Num[yy] <<endl;
if(xx < 0 || xx >= n || yy < 0 || yy >= n) continue;
if(s + Map[xx][yy] > Num[xx][yy])
{
//cout << 1 <<endl;
Num[xx][yy] = s+Map[xx][yy];
Q.push(Node(xx,yy));
}
}
}
return Num[n-1][n-1];
} void RedMap(int n)
{
int bx = 0, by = 0;
for(int i = 1; i <= n; ++i)
{
int xx = bx, yy = by;
for(int j = 1; j <= i; ++j)
{
cin >> Map[xx][yy];
//cout << xx<< " " << yy << endl;
xx--, yy++;
}
bx++;
}
bx --, by ++;
for(int i = 1; i <= n-1; ++i)
{
int xx = bx, yy = by;
for(int j = 1; j <= n-i; ++j)
{
cin >> Map[xx][yy];
//cout << xx<<" " << yy << endl;
xx--, yy++;
}
by++;
}
}
int main()
{
int t, n;
cin >> t;
for(int kase = 1; kase <= t; ++kase)
{
cin >> n;
Init();
RedMap(n);
printf("Case %d: %d\n",kase, BFS(n));
/*for(int i = 0; i < n; ++i)
{
for(int j = 0; j < n; ++j)
cout << Num[i][j] << " ";
cout << endl;
}*/
}
}
LightOJ1004的更多相关文章
- [LightOJ1004]Monkey Banana Problem(dp)
题目链接:http://lightoj.com/login_main.php?url=volume_showproblem.php?problem=1004 题意:数塔的变形,上面一个下面一个,看清楚 ...
- lightoj1004【基础DP】
从低端到顶端求个最大值: 思路: 基础DP,递推 #include<cstdio> #include<queue> #include<map> #include&l ...
随机推荐
- 细说JDK日志组件
1. 概述 JDK自带的日志组件在包java.util.logging下,如图: 2. 架构如上图所示,JDK日志组件核心元素包括:Logger,Handler,Filter和Formatter,他们 ...
- GeoGlobe Server使用问题收集
本人在做数字县区过程中,需要吉奥GeoGlobe Server发布数据,期间遇到些平台问题.故立此帖,作为参考. 1 字段限制: GeoGlobe 5.2部署在我的服务器Windows Server ...
- vue 中 使用百度编辑器 UEditor
(单页应用,多编辑器也可行) 新建一个Ueditor.vue组件对象,该组件用来封装ueditor,用来进行复用. <template> <div> <!--下面通过传递 ...
- Extjs.net Button点击下载jpg图片
<ext:Button ID=" AutoPostBack="false"> <DirectEvents> <Click OnEvent=& ...
- Spring AutoWire
AutoWire 有 ByType ,ByName两种主要使用方式 public class Boss { @Autowired private Car car; public Car getCar( ...
- Xml的转义字符--约束-xml解析器
XML解析器:Dom适合增删改查(crud),缺点就是内存消耗大: Sax:内存消耗非常小,解析速度快,但是不适合增删改:
- java语言什么时候诞生的?
java语言什么时候诞生的?创始人是谁?何时发布的? Java编程语言是sun Microsystems公司JamesGosling在1990年创建的1995年公布于世
- Django学习手册 - 基于requests API验证(二)
原理分析: API接口验证 1.一个认证的key server端 和 client端都必须有这么一个认证key. 2.认证登录的时间限定 3.保存已验证的信息,在以后的验证不能再次登录 client ...
- 使用jQuery重置(reset)表单的方法
由于JQuery中,提交表单是像下面这样的: 代码如下: $('#yigeform').submit() 所以,想当然的认为,重置表单,当然就是像下面这样子喽: 代码如下: $('#yigeform' ...
- 使用Numpy将数据集中的data和target同时shuffle
假设现在有图像数据imgs和对应标签targets.数据维度分别如下 imgs.shape = (num, channel, width, height) targets.shape = (num, ...