PKU ACM 1163
2009-12-26 14:03
375 查看
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 program that calculates the highest sum of numbers passed on a route that starts at the top and ends somewhere on the base. Each step can go either diagonally down to the left or diagonally down to the right.
动态规划问题,建立一个数组,从下到上,保存各节点的最大值
#include <stdio.h> #define MAX 100 int input[MAX][MAX]; int main() { int n,i,j; scanf("%d",&n); for(i=0;i<n;i++) for(j=0;j<i+1;j++) scanf("%d",input[i]+j); for(i=n-2;i>=0;i--) for(j=0;j<i+1;j++) input[i][j]+=input[i+1][j]>input[i+1][j+1]?input[i+1][j]:input[i+1][j+1]; printf("%d",input[0][0]); return 0; }
相关文章推荐
- acm--pku--1163
- PKU ACM 1163-The Triangle
- Pku acm 1163 the Triangle
- pku acm 1035
- http://acm.pku.edu.cn/JudgeOnline/
- pku acm 1042 Gone Fishing
- ACM PKU POJ 1112 解题报告
- http://acm.pku.edu.cn/JudgeOnline/problem?id=1284 (原根)
- http://acm.pku.edu.cn/JudgeOnline/problem?id=3667 区间更新+求满足长短的最左区间
- PKU ACM 1080 源代码
- pku ACM 1125
- pku acm 1922 Ride to School
- POJ 1002求487-3279解题报告——【PKU ACM】
- pku acm 1006
- PKU比较好的题目分类,这个将作为我学习ACM的计划
- Pku 1163 the Triangle
- Pku acm 1579 Function Run Fun
- PKU ACM 1012 JOSEPH问题
- Pku acm 1458 Common Subsequence 动态规划题目解题报告(五)
- Pku acm 2418 Hardwood Species 排序算法解题报告(六) ----二叉查找数(BST)