POJ 1163 The Triangle
来源:互联网 发布:淘宝五金店铺代理 编辑:程序博客网 时间:2024/06/05 15:14
题目大意: 从三角形顶部数字走,每次只能走到这个数字的左下角或者右下角的数字,直到底部,计算走过的线路的数字之和,求这个和的最大值
解题思路: 这道题如果用枚举法(暴力思想),在数塔层数稍大的情况下(如31),则需要列举出的路径条数将是一个非常庞大的数目(2^30= 1024^3 > 10^9=10亿)。
因此我们可以从下往上推,相邻的两个数中找较大的与上层相加,得出的结果相邻的两个数中再找较大的与上层相加,以此类推。
#include <cstdio>#include <algorithm>using namespace std;int main() { int N; while (scanf("%d", &N) != EOF) { int DP[110][110]; for (int i = 0; i < N; i++) for (int j = 0; j <= i; j++) scanf("%d", &DP[i][j]); for (int i = N-2; i >= 0; i--) for (int j = 0; j <= i; j++) DP[i][j] += max(DP[i+1][j], DP[i+1][j+1]); printf("%d\n", DP[0][0]); } return 0;}
0 0
- The Triangle--poj--1163
- POJ 1163 The Triangle
- poj 1163 The Triangle
- Poj 1163 The Triangle
- poj 1163 The Triangle
- poj 1163 The Triangle
- poj 1163 The Triangle
- POJ 1163 The Triangle
- poj 1163 The Triangle
- POJ 1163 The Triangle
- POJ 1163 The Triangle
- poj 1163 The Triangle
- poj-1163 The Triangle
- poj 1163 The Triangle
- POJ-1163-The Triangle
- poj 1163 The Triangle
- POJ-1163-The Triangle
- poj 1163 The Triangle
- Just a Hook 线段树--成段更新
- HDU-4777 Rabbit Kingdom
- C++ 预处理、编译、汇编、链接
- UIImageView动画 、自定义View 和手势的简单实用 Tom 猫 全部功能实现
- 软件测试学习笔记2015/8/24
- POJ 1163 The Triangle
- hdu 2899 Strange fuction(二分+数学)
- 【cocos2d-x 3.7 飞机大战】 决战南海I (六) 保存玩家数据
- TextView属性
- HDOJ 2588 GCD(欧拉函数)
- 人间自有真情在
- 套接字编程简介
- 欧拉函数
- 【cocos2d-x 3.7 飞机大战】 决战南海I (七) 控制器的实现