#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的更多相关文章

  1. [LightOJ1004]Monkey Banana Problem(dp)

    题目链接:http://lightoj.com/login_main.php?url=volume_showproblem.php?problem=1004 题意:数塔的变形,上面一个下面一个,看清楚 ...

  2. lightoj1004【基础DP】

    从低端到顶端求个最大值: 思路: 基础DP,递推 #include<cstdio> #include<queue> #include<map> #include&l ...

随机推荐

  1. Spark源码剖析 - SparkContext的初始化(九)_启动测量系统MetricsSystem

    9. 启动测量系统MetricsSystem MetricsSystem使用codahale提供的第三方测量仓库Metrics.MetricsSystem中有三个概念: Instance:指定了谁在使 ...

  2. FastJson用法

    namespace test { class Program { static void Main(string[] args) { var zoo1 = new zoo(); zoo1.animal ...

  3. SQL行列转置

    今天给公司同事们出了一道例行考试题,要求写一句SQL语句从上面表转换为下面表,经过艰难思索,一个同事做了出来. 小区             总数    A类车 B类车 C类车建业森林半岛     2 ...

  4. mvc 分页PagedList简单使用

    1.nuget下载PagedList包 2.PageListHelper类: using PagedList; using System; using System.Collections.Gener ...

  5. kettle中的合并记录使用记录

    注意:合并记录的使用前提是2个数据源都按比较关键字排过序,否则合并之后的数据不准确,可能会多出很多. 该步骤用于将两个不同来源的数据合并,这两个来源的数据分别为旧数据和新数据,该步骤将旧数据和新数据按 ...

  6. JSON格式说明

    JSON的优点 相比XML拥有更简单的格式. 不同WEB浏览器处理的结果一样. 纯文本数据交换格式. JSON格式特点 {} 对象定义域 key:value 定义属性 key 字符串格式,value ...

  7. 推荐前端框架 & 模板

    BootStrap Semantic UI Pure Amazeui(前后端都有,很丰富) amazeui http://tpl.amazeui.org AdminLTE AdminLTE https ...

  8. python(三)@staticmethod和@classmethod使用和区别

    转载自[1] 一般要用某个类的方法,先要实例这个类. 但是可以通过@staticmethod和@classmethod,直接用“类.方法()”来调用这个方法. 而 @staticmethod和@cla ...

  9. Android逆向基础----Android Dalvik虚拟机

    Android Dalvik虚拟机的特点: l  体积小,占用内存空间小. l  专有DEX可执行文件. l  常量池采用32位索引值,寻址类方法名,字段名,常量更快. l  基于寄存器架构,并拥有一 ...

  10. python 微信跳一跳辅助 复现

    本来用的是苹果ios得手机,但是步骤较为复杂,没有吃透,最后妥协用了android的机器搞得. 首先找到大牛的github https://github.com/wangshub/wechat_jum ...