nyoj 18 The Triangle 动态规划

和nyoj613(免费馅饼)一样的原理  从下 网上依次遍历 存贮最大值

#include <stdio.h>
#include <algorithm>
using namespace std;
int main()
{
	int n,num[105][105]={0};
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	for(int j=1;j<=i;j++)
	scanf("%d",&num[i][j]);
	for(int i=n-1;i>=0;i--)
	for(int j=1;j<=i;j++)
	num[i][j]=num[i][j]+max(num[i+1][j],num[i+1][j+1]);
	printf("%d\n",num[1][1]);
	return 0;
}
时间: 2024-10-12 20:24:07

nyoj 18 The Triangle 动态规划的相关文章

LeetcodeOJ: Triangle 动态规划

Total Accepted: 31557 Total Submissions: 116793 Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjacent numbers on the row below. [ [2], [3,4], [6,5,7], [4,1,8,3] ] The minimum path sum from top to bottom is

poj 1163 The Triangle (动态规划)

The Triangle Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 37778   Accepted: 22685 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

NYOJ 16 The Triangle

The Triangle 时间限制:1000 ms  |  内存限制:65535 KB 难度:4 描述 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 t

nyoj 311-完全背包 (动态规划, 完全背包)

311-完全背包 内存限制:64MB 时间限制:4000ms Special Judge: No accepted:5 submit:7 题目描述: 直接说题意,完全背包定义有N种物品和一个容量为V的背包,每种物品都有无限件可用.第i种物品的体积是c,价值是w.求解将哪些物品装入背包可使这些物品的体积总和不超过背包容量,且价值总和最大.本题要求是背包恰好装满背包时,求出最大价值总和是多少.如果不能恰好装满背包,输出NO 输入描述: 第一行: N 表示有多少组测试数据(N<7). 接下来每组测试数

nyoj 79 拦截导弹 (动态规划)

题目链接:http://acm.nyist.net/JudgeOnline/problem.php?pid=79 题意即求最长单调递减子序列 #include<iostream> #include<cstdio> #include<cstring> using namespace std; #define N 22 int h[N]; int d[N]; int main() { freopen("d:\\in.txt", "r"

NYOJ 110剑客决斗(动态规划)

描述 在路易十三和红衣主教黎塞留当权的时代,发生了一场决斗.n个人站成一个圈,依次抽签.抽中的人和他右边的人决斗,负者出圈.这场决斗的最终结果关键取决于决斗的顺序.现书籍任意两决斗中谁能胜出的信息,但"A赢了B"这种关系没有传递性.例如,A比B强,B比C强,C比A强.如果A和B先决斗,C最终会赢,但如果B和C决斗在先,则最后A会赢.显然,他们三人中的第一场决斗直接影响最终结果. 假设现在n个人围成一个圈,按顺序编上编号1~n.一共进行n-1场决斗.第一场,其中一人(设i号)和他右边的人

[LeetCode][JavaScript]Triangle

Triangle Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjacent numbers on the row below. For example, given the following triangle [ [2], [3,4], [6,5,7], [4,1,8,3] ] The minimum path sum from top to bottom

leetCode(47):Triangle

Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjacent numbers on the row below. For example, given the following triangle [ [2], [3,4], [6,5,7], [4,1,8,3] ] The minimum path sum from top to bottom is 11 (i

动态规划第五讲——leetcode上的题目动态规划汇总(上)

本节,我们将对leetcode上有关DP问题的题目做一个汇总和分析. 1.题目来源 Interleaving String 动态规划 二叉树 Unique Binary Search Trees 动态规划 二叉树 Word Break 动态规划 N/A Word Break II 动态规划 N/A Palindrome Partitioning 动态规划 N/A Palindrome Partitioning II 动态规划 N/A Triangle 动态规划 N/A Distinct Subs