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 ...
随机推荐
- windows server 2008r2x64 安全配置
管理工具--本地安全策略 1.帐户策略--密码策略 密码长度最小值:8 强制密码历史:1 2.本地安全策略--安全选项 交互式登录:不显示最后的用户名:已启用
- tedu训练营day02
1.Linux命令 1.关机.重启 关机 :init 0 重启 :init 6 2.rm 1.rm -rf 文件/目录 r :递归删除文件夹内的子文件夹 f :强制删除,force 2.练习 1.在用 ...
- springboot(十六):springboot整合shiro
数据库有五张表(userInfo,uerrole,role,rolepermission,permission) userInfo(id,username,password) userrole(uid ...
- JDK8新特性02 Lambda表达式02_Lambda语法规则
//函数式接口:只有一个抽象方法的接口称为函数式接口. 可以使用注解 @FunctionalInterface 修饰 @FunctionalInterface public interface MyF ...
- 认证加密算法php hash_hmac和java hmacSha1的问题
public class Test{ public static void main(String[] args) throws Exception { String postString = &qu ...
- GCC编译器原理(二)------编译原理一:目标文件
一.目标文件 在 UNIX® 和 Linux® 中,任何事物都是文件.UNIX 和 Linux 编程实际上是编写处理各种文件的代码.系统由许多类型的文件组成,但目标文件具有一种特殊的设计,提供了灵活和 ...
- C# MVC EF框架 用事务
using System.Transactions; [HttpPost] public JsonResult Update(InfoModel list) { using (TransactionS ...
- springboot03-unittest mockmvc单元测试
整个项目结构: 定义user实体类 package com.mlxs.springboot.dto; import java.util.HashMap; import java.util.Map; / ...
- 利用PHP+MySql+Ajax操作实现年月日联动功能
PHP+MySql+Ajax实现年月日的三级联动 <!DOCTYPE html><html> <head> <meta charset=& ...
- 理解PHP中的会话控制
会话控制是一种跟踪用户的通信方式,使用会话控制主要基于以下几点:由于http协议的无状态性,使得不能通过协议来建立两次请求之间的关联:对于通常的页面之间的数据传递方式get和post而言,主要处理参数 ...