project euler 18 Maximum path sum I
来源:互联网 发布:mac 安全模式 编辑:程序博客网 时间:2024/06/11 10:08
题目:
https://projecteuler.net/problem=18
题意:
By starting at the top of the triangle below and moving to adjacent numbers on the row below, the maximum total from top to bottom is 23.
That is, 3 + 7 + 4 + 9 = 23.
Find the maximum total from top to bottom of the triangle below:
NOTE: As there are only 16384 routes, it is possible to solve this problem by trying every route. However, Problem 67, is the same challenge with a triangle containing one-hundred rows; it cannot be solved by brute force, and requires a clever method! ;o)
给出一个15行的数字三角形,从顶端往下走,从当前位置只能走到下一行与当前位置相邻的两个点。选择一条路径,使路径经过点的权值和最大
思路:
定义
这里重复利用了
代码:
#include <bits/stdc++.h>using namespace std;typedef long long ll;const int N = 100 + 10;int dp[N][N];int main(){ freopen("f:\\data.txt", "r", stdin); int n = 15; for(int i = 1; i <= n; ++i) for(int j = 1; j <= i; ++j) scanf("%d", &dp[i][j]); for(int i = 1; i <= n; ++i) for(int j = 1; j <= i; ++j) dp[i][j] += max(dp[i-1][j-1], dp[i-1][j]); int ans = 0; for(int i = 1; i <= n; ++i) ans = max(ans, dp[n][i]); printf("%d\n", ans); return 0;}
阅读全文
0 0
- project euler 18 Maximum path sum I
- Maximum path sum I [Project Euler.Problem 18]
- Project Euler:Problem 18 Maximum path sum I
- Project Euler Problem 18 Maximum path sum I
- Project Euler 题解 #18 & #67 Maximum path sum
- Project Euler:Problem 67 Maximum path sum II
- Project Euler Problem 67 Maximum path sum II
- Maximum path sum I
- Problem 18:Maximum path sum I
- Maximum path sum I Problem 18
- PE 18 Maximum path sum I
- No18:Maximum path sum I
- projecteuler---->problem=18----Maximum path sum I
- 欧拉项目第18题Maximum path sum I
- Problem 18 Maximum path sum I (dp)
- [projecteuler]Maximum path sum I,II
- Project Euler:Problem 81 Path sum: two ways
- Project Euler:Problem 82 Path sum: three ways
- [大数据基础-junit]junit4入门基础
- Spring DAO(3):Spring 事务管理
- java插入排序算法2
- ARM编程模式和7种模式
- java还有这两个位运算符^和~
- project euler 18 Maximum path sum I
- 第六篇实训博客
- Sanic学习---安装部署
- 字符串替换
- 孤儿怨——观后感
- 190. Reverse Bits
- Micro Python 入门教程---第三个Micro Python LCD5110显示6x8字符
- Go语言将10进制数转换为16进制数写入文件
- CommonJs和AMD(requireJS)模块化