lightoj 1004
很水的一个dp
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
const int N=100;
int a[2*N+5][N+5],dp[2*N+5][N+5];
int main()
{
int T,n,i,j,ca=0;
cin>>T;
while(T--)
{
cin>>n;
memset(a,0,sizeof(a));
memset(dp,0,sizeof(dp));
for( i=1;i<=n;i++)
for(j=1;j<=i;j++)
cin>>a[i][j];
for(i=n+1;i<=2*n-1;i++)
for(j=1;j<=2*n-i;j++)
cin>>a[i][j];
for(i=1;i<=n;i++)
{
for(j=1;j<=i;j++)
dp[i][j]=max(dp[i-1][j-1],dp[i-1][j])+a[i][j];
}
for(i=n+1;i<=2*n-1;i++)
{
for(j=1;j<=2*n-i;j++)
dp[i][j]=max(dp[i-1][j],dp[i-1][j+1])+a[i][j];
}
ca++;
cout<<"Case "<<ca<<": "<<dp[2*n-1][1]<<endl;
}
return 0;
}
lightoj 1004的更多相关文章
- Monkey Banana Problem LightOJ - 1004
Monkey Banana Problem LightOJ - 1004 错误记录: 1.数组开小2.每组数据数组没有清空 #include<cstdio> #include<cst ...
- lightoj 1004 dp:数字三角形
题目链接:http://lightoj.com/volume_showproblem.php?problem=1004 #include <cstdio> #include <cst ...
- Lightoj 1004 - Monkey Banana Problem
题目链接:http://acm.hust.edu.cn/vjudge/contest/121396#problem/F http://lightoj.com/volume_showproblem.ph ...
- (LightOJ 1004) Monkey Banana Problem 简单dp
You are in the world of mathematics to solve the great "Monkey Banana Problem". It states ...
- lightoj刷题日记
提高自己的实力, 也为了证明, 开始板刷lightoj,每天题量>=1: 题目的类型会在这边说明,具体见分页博客: SUM=54; 1000 Greetings from LightOJ [简单 ...
- 区间DP LightOJ 1422 Halloween Costumes
http://lightoj.com/volume_showproblem.php?problem=1422 做的第一道区间DP的题目,试水. 参考解题报告: http://www.cnblogs.c ...
- bzoj 1004 Cards
1004: [HNOI2008]Cards Description 小春现在很清闲,面对书桌上的N张牌,他决定给每张染色,目前小春只有3种颜色:红色,蓝色,绿色.他询问Sun有 多少种染色方案,Sun ...
- Codeforces Round #262 (Div. 2) 1004
Codeforces Round #262 (Div. 2) 1004 D. Little Victor and Set time limit per test 1 second memory lim ...
- LightOj 1298 - One Theorem, One Year(DP + 欧拉)
题目链接:http://lightoj.com/volume_showproblem.php?problem=1298 题意:给你两个数 n, p,表示一个数是由前 k 个素数组成的,共有 n 个素数 ...
随机推荐
- mysql---索引及explain的作用
索引:是一种数据结构,以增加存储开销和减慢DML(增.删.改)操作来提高查询速度. 常见的索引结构:btree索引(myisam,innodb,memory,heap),hash索引(memory,h ...
- Java security MD5加密算法
利用java.security对字符串进行MD5加密: import java.security.MessageDigest; import java.security.NoSuchAlgorithm ...
- Sass:一种CSS预处理器语言
http://sass-lang.com/ Sass是一种CSS预处理器语言,通过编程方式生成CSS代码.因为可编程,所以操控灵活性自由度高,方便实现一些直接编写CSS代码较困难的代码. 同时,因为S ...
- 用LinqToExcel处理有标题表格的数据
1. 先根据表格标题定义一个类. public class News { public string Title { set; get; } public string Content { set; ...
- 深入理解javascript中的闭包!(转)
1.闭包的经典错误 假如页面上有若干个div,我们想给它每个绑定一个onclick方法,于是有了下面的代码. function A(){ var divs=document.getElementsBy ...
- 【原】yield的最基本用法
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Itca ...
- jquery中交替点击事件toggle方法的使用示例
jquery中交替点击事件toggle方法中有两个参数,分别是要交替执行的事件.如果不传参默认是显示隐藏功能,下面有个不错的示例,感兴趣的朋友可以参考下 复制代码代码如下: $('#clickId‘) ...
- EventLog组件
1.使用EventLog组件读写事件日志 SourceExists方法 确定事件源是否已在本地计算机上注册 DeleteEventSource方法 用于从事件日志中移除应用程序的事件源注册 pri ...
- HTTP错误 404.17
HTTP错误 404.17 - Not Found" IIS 7.5 请求的内容似乎是脚本,因而将无法由静态文件处理程序来处理 出现这种情况的原因通常是因为先安装了Framework,后 ...
- Oracle数据库安装完成之后的启动操作
由于是菜鸟,在 完成Oracle数据库的安装之后,不知道该怎么启动.在经过一番折腾之后明白了其中的一些道理,总结如下: 其实Oracle数据库和Mysql数据库的启动都是相同的原理. Mysql数据库 ...