#include<iostream>
#include<stdio.h>
#include<algorithm> using namespace std; int max(int sum1,int sum2);
int dp(int i,int j,int **,int num,int **);
int main()
{
//freopen("acm.acm","r",stdin);
int num;
cin>>num;
int * * a;
int * * ans;
a = new int *[num];
ans = new int * [num];
int i,j;
for(i = ; i < num; i ++)
{
a[i] = new int[num];
}
for(i = ; i < num; i ++)
ans[i] =new int[num];
for(i = ; i < num; i ++)
for(j = ; j <= i; j ++)
{
cin>>a[i][j];
ans[i][j] = -;
}
// for(i = 0; i <num; i ++)
// {
// for(j = 0; j <= i; j ++)
// cout<<a[i][j]<<" ";
// cout<<endl;
// }
cout<<a[][] + dp(,,a,num,ans)<<endl;
}
int dp(int i,int j,int **a,int num,int **ans)
{
int sum1 = ;
int sum2 = ;
if(i + <= num -)
{
if(ans[i+][j] != -)
sum1 = a[i+][j]+ans[i+][j];
else
sum1 = a[i+][j]+dp(i+,j,a,num,ans);
if(ans[i+][j+] != -)
sum2 = a[i+][j+]+ans[i+][j+];
else
sum2 = a[i+][j+]+dp(i+,j+,a,num,ans);
ans[i][j] = max(sum1,sum2);
return max(sum1,sum2);
}
return ; }
int max(int sum1,int sum2)
{
//return sum1 > sum2 ? sum1 : sum2;
if(sum1>sum2)
return sum1;
else
return sum2;
}

关注我的公众号,当然,如果你对Java, Scala, Python等技术经验,以及编程日记,感兴趣的话。

技术网站地址: vmfor.com

POJ 1163的更多相关文章

  1. poj 1163 The Triangle &amp;poj 3176 Cow Bowling (dp)

    id=1163">链接:poj 1163 题意:输入一个n层的三角形.第i层有i个数,求从第1层到第n层的全部路线中.权值之和最大的路线. 规定:第i层的某个数仅仅能连线走到第i+1层 ...

  2. POJ 1163 The Triangle(简单动态规划)

    http://poj.org/problem?id=1163 The Triangle Time Limit: 1000MS   Memory Limit: 10000K Total Submissi ...

  3. OpenJudge/Poj 1163 The Triangle

    1.链接地址: http://bailian.openjudge.cn/practice/1163 http://poj.org/problem?id=1163 2.题目: 总时间限制: 1000ms ...

  4. POJ 1163 The Triangle【dp+杨辉三角加强版(递归)】

    The Triangle Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 49955   Accepted: 30177 De ...

  5. POJ 1163 The Triangle 简单DP

    看题传送门门:http://poj.org/problem?id=1163 困死了....QAQ 普通做法,从下往上,可得状态转移方程为: dp[i][j]= a[i][j] + max (dp[i+ ...

  6. POJ 1163 数字三角形

    Portal:http://poj.org/problem?id=1163 DP经典题,IOI94考题,在各大OJ上都有 #include<iostream> #include<al ...

  7. dp入门--poj 1163数塔

                                                                                                        ...

  8. POJ 1163:The Triangle

    Description 7 3 8 8 1 0 2 7 4 4 4 5 2 6 5 (Figure 1) Figure 1 shows a number triangle. Write a progr ...

  9. poj 1163 The Triangle

    The Triangle Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 43809   Accepted: 26430 De ...

  10. 递推DP POJ 1163 The Triangle

    题目传送门 题意:找一条从顶部到底部的一条路径,往左下或右下走,使得经过的数字和最大. 分析:递推的经典题目,自底向上递推.当状态保存在a[n][j]时可省去dp数组,空间可优化. 代码1: /*** ...

随机推荐

  1. 2018.07.29~30 uoj#170. Picks loves segment tree VIII(线段树)

    传送门 线段树好题. 维护区间取两种最值,区间加,求区间两种历史最值,区间最小值. 自己的写法调了一个晚上+一个上午+一个下午+一个晚上并没有调出来,90" role="prese ...

  2. cgo -rpath指定动态库路径

    // #cgo CFLAGS: -Wall // #cgo LDFLAGS: -Wl,-rpath="/home/liuliang/ffmpeg-build/lib" // #cg ...

  3. Tomcat 环境变量配置

    1.变量和常量 i 和 0 2.环境变量 cmd >set 查看所有环境变量 %PATH% 系统指定可执行文件的搜索路径,可以是 .exe .bat String path=“C:\WINDOW ...

  4. Object-C中 - self 和super 的含义

    //super:父类         //self:自己              //自己理解         //以MobilePhone为例,父类为NSObject         //在类方法 ...

  5. C#-VS字符串、日期、时间和时间段

    小知识 哈希表,内存中的对象,用速度很快的哈希表当字典表,记录主键和内容. @,遇到转义字符,不转义,直接输出,即就是.转义字符是反斜杠/ 全部的内置类型都用类和结构描述.值类型用结构,引用类型用类. ...

  6. 一次简单完整的自动化登录测试-基于python+selenium进行cnblog的自动化登录测试

    Web登录测试是很常见的测试,手动测试大家再熟悉不过了,那如何进行自动化登录测试呢!本文就基于python+selenium结合unittest单元测试框架来进行一次简单但比较完整的cnblog自动化 ...

  7. noip第11课作业

    1.    数字比较 定义一个函数check(n,d),让它返回一个布尔值,如果数字d在正整数n的某位中出现则返回true,否则返回false. 例如:check(325719,3)==true:ch ...

  8. PHP 7 安装 Memcache 和 Memcached 总结

    Memcache 与 Memcached 的区别 Memcached 是 Memcache 的升级版,优化了 Memcache,并增加了一些操作方法.所以现在基本都是用最近版本的. PHP 7 下安装 ...

  9. dubbo 源码编译记录

    DUBBO是一个分布式服务框架,致力于提供高性能和透明化的RPC远程服务调用方案,是阿里巴巴SOA服务化治理方案的核心框架,阿里内部采用sofa框架,同属于分布式RPC框架,dubbo开源,而sofa ...

  10. netty--NioEventLoop滴干活

    netty是最近项目要用到的nio框架,找了各种资料,发现称赞它的有点多,所以决定用它:其实也就二选一嘛,mina或netty或自己写.对于mina,也不熟,不过看各种介绍,貌似netty干活还是很不 ...