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 ...
随机推荐
- linux_网易云音乐安装
使用命令安装一些基本包$ sudo apt install devscripts equivs git
- VS2010显示行号
选项->文本编辑器->如果使用C#开发选择C#->勾选行号->确定
- 哈希函数(hash函数)
hash,—般译为“散列”,也可以直接音译为“哈希”,是对输入的任意长度(又称预映射),通过哈希算法,转换成固定长度的哈希值输出.这种转换是一种压缩映射,即,哈希值空间通常比输入空间小得多,不同的输入 ...
- Linux之Ubuntu下DSL拨号上网
可视化桌面配置方法 1.编辑连接 2.选择 增加 3.选择 DSL 4.选择 新建连接[cmcc@gx属于移动校园用户的ISP指定后缀] 6.OK 当然,还有其他拨号上网的办法: [Linux/Ubu ...
- Python之线程 1 - 线程基本概念
一 背景知识 1.进程 2.有了进程为什么还要线程 3.线程的出现 二 线程和进程的关系 三 线程的特点 四 线程的实际应用场景 五 内存中的线程 六 用户级线程和内核级线程(了解) 1.用户级线程 ...
- 迅为开发板4412开发板-ANROID系统的烧写方法分享
详情了解: http://topeetboard.com 更多了解:https://arm-board.taobao.com 一.OTG接口烧写方式 通过该方式可以烧写 Android4.0.3 ...
- python中的私有变量
class Test1: def f1(self): self.name ="张三" self.__age = 20 #使用名称变形实现私有变量 print(self.name) ...
- 模拟post表单提交参数
Content-Type: application/x-www-form-urlencoded;charset=utf-8
- Django中session的基础了解
基于cookie做用户验证时:敏感信息不适合放在cookie中 session依赖cookie session原理 cookie是保存在用户浏览器端的键值对 session是保存在服务器端的键值对 s ...
- ueditor取消文本编辑器的自动拉伸高度、宽度。
1.首先引入富文本编辑器 <script type="text/javascript" src="<%=basePath%>js/ueditor/ued ...