lightoj1004【基础DP】
从低端到顶端求个最大值;
思路:
基础DP,递推
#include<cstdio>
#include<queue>
#include<map>
#include<string>
#include<string.h>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long LL;
const int INF=0x3f3f3f3f;
const LL mod=1e9+7; int a[110][110];
int dp[110][110]; int main()
{
int T,cas=1;
int n;
scanf("%d",&T);
while(T--)
{
scanf("%d",&n);
memset(a,0,sizeof(a));
for(int i=1;i<=2*n-1;i++)
{
if(i<=n)
{
for(int j=1;j<=i;j++)
scanf("%d",&a[i][j]);
}
else
{
for(int j=1;j<=(2*n-i);j++)
scanf("%d",&a[i][j]);
}
}
memset(dp,0,sizeof(dp));
dp[1][1]=a[1][1];
for(int i=1;i<=n;i++)
for(int j=1;j<=i;j++)
dp[i][j]=a[i][j]+max(dp[i-1][j],dp[i-1][j-1]);
for(int i=n+1;i<=2*n-1;i++)
for(int j=1;j<=(2*n-i);j++)
dp[i][j]=a[i][j]+max(dp[i-1][j],dp[i-1][j+1]);
printf("Case %d: ",cas++);
printf("%d\n",dp[2*n-1][1]);
}
return 0;
}
lightoj1004【基础DP】的更多相关文章
- 基础dp
队友的建议,让我去学一学kuangbin的基础dp,在这里小小的整理总结一下吧. 首先我感觉自己还远远不够称为一个dp选手,一是这些题目还远不够,二是定义状态的经验不足.不过这些题目让我在一定程度上加 ...
- 基础DP(初级版)
本文主要内容为基础DP,内容来源为<算法导论>,总结不易,转载请注明出处. 后续会更新出kuanbin关于基础DP的题目...... 动态规划: 动态规划用于子问题重叠的情况,即不同的子问 ...
- hdu 5586 Sum 基础dp
Sum Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Problem Desc ...
- hdu 4055 Number String (基础dp)
Number String Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)To ...
- 训练指南 UVA - 10917(最短路Dijkstra + 基础DP)
layout: post title: 训练指南 UVA - 10917(最短路Dijkstra + 基础DP) author: "luowentaoaa" catalog: tr ...
- 训练指南 UVA - 11324(双连通分量 + 缩点+ 基础DP)
layout: post title: 训练指南 UVA - 11324(双连通分量 + 缩点+ 基础DP) author: "luowentaoaa" catalog: true ...
- 「kuangbin带你飞」专题十二 基础DP
layout: post title: 「kuangbin带你飞」专题十二 基础DP author: "luowentaoaa" catalog: true tags: mathj ...
- M - 基础DP
M - 基础DP Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Descriptio ...
- hdu 4489 The King’s Ups and Downs(基础dp)
The King’s Ups and Downs Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java ...
随机推荐
- 【MatConvNet】配置GPU
参照大神的方法:http://www.th7.cn/system/win/201603/155182.shtml 第一步:需要安装cuda.VS2013:cuda默认路径,注意cuda版本和GPU要匹 ...
- BestCoder #47 1001&&1002
[比赛链接]cid=608">clikc here~~ ps:真是wuyu~~做了两小时.A出两道题,最后由于没加longlong所有被别人hack掉!,最后竟然不知道hack别人不成 ...
- SPOJ - GSS1&&GSS3
GSS1 #include<cstdio> #include<iostream> #define lc k<<1 #define rc k<<1|1 u ...
- 在Win7创建WiFi热点
1.在开始菜单搜索cmd 2.运行cmd 3.输入以下命令,注意:Your-WiFi-Name和Your-WiFi-Password分别为WiFi名称和密码 netsh wlan set hosted ...
- Centos7利用kvm搭建Windows虚拟机
这几天玩了一下kvm虚拟化,真的很有意思,我把这几天踩的坑,还有收获,都记录下来,作为以后的复习和检查. 首先说一下我的基本逻辑,我有一台win7的笔记本,我的底层虚拟化是使用VMWare构建的Cen ...
- appcompat_v7出现红叉解决方法
右键属性,java build path 勾选Android5.5.2
- java IO流文件的读写具体实例(转载)
引言: 关于java IO流的操作是非常常见的,基本上每个项目都会用到,每次遇到都是去网上找一找就行了,屡试不爽.上次突然一个同事问了我java文件的读取,我一下子就懵了第一反应就是去网上找,虽然也能 ...
- c# 容器类简介
c# 容器类简介 C# 中主要有两类容器:一个是 System.Array 类(参阅:http://msdn.microsoft.com/library/default.asp?url=/libr ...
- im资源
https://github.com/oikomi/FishChatServer https://github.com/subrosa-io https://github.com/WhisperSys ...
- MAC 地址解析
windows cmd 命令行通过 ipconfig /all:查看本地的 ip 地址以及 mac地址: MAC 地址的前三个字节代表厂商: 00:50:56/00:0c:29:vmware 公司 c ...