POJ - 1163 The Triangle 【动态规划】
一、题目
二、分析
动态规划入门题。
状态转移方程$$DP[i][j] = A[i][j] + max(DP[i-1][j], DP[i][j])$$
三、AC代码
1 #include <cstdio>
2 #include <cstring>
3 #include <iostream>
4 #include <algorithm>
5 #include <vector>
6 #include <cmath>
7
8 using namespace std;
9 #define ll long long
10 #define Min(a,b) ((a)>(b)?(b):(a))
11 #define Max(a,b) ((a)>(b)?(a):(b))
12 const int MAXN = 100;
13 int A[MAXN + 13][MAXN + 13];
14 int Ans[2][MAXN + 13];
15
16 int main()
17 {
18 int N;
19 while(scanf("%d", &N) != EOF) {
20 memset(A, 0, sizeof(A));
21 memset(Ans, 0, sizeof(Ans));
22 for(int i = 1; i <= N; i++) {
23 for(int j = 1; j <= i; j++) {
24 scanf("%d", &A[i][j]);
25 }
26 }
27 for(int i = 1; i <= N; i++) {
28 for(int j = 1; j <= i; j++) {
29 Ans[i&1][j] = A[i][j] + Max(Ans[(i-1)&1][j-1], Ans[(i-1)&1][j]);
30 }
31 }
32 int ans = 0;
33 for(int i = 1; i <= N; i++) {
34 ans = Max(ans, Ans[N&1][i]);
35 }
36 printf("%d\n", ans);
37 }
38 return 0;
39 }
POJ - 1163 The Triangle 【动态规划】的更多相关文章
- POJ 1163 The Triangle(简单动态规划)
http://poj.org/problem?id=1163 The Triangle Time Limit: 1000MS Memory Limit: 10000K Total Submissi ...
- poj 1163 The Triangle &poj 3176 Cow Bowling (dp)
id=1163">链接:poj 1163 题意:输入一个n层的三角形.第i层有i个数,求从第1层到第n层的全部路线中.权值之和最大的路线. 规定:第i层的某个数仅仅能连线走到第i+1层 ...
- POJ 1163 The Triangle【dp+杨辉三角加强版(递归)】
The Triangle Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 49955 Accepted: 30177 De ...
- OpenJudge/Poj 1163 The Triangle
1.链接地址: http://bailian.openjudge.cn/practice/1163 http://poj.org/problem?id=1163 2.题目: 总时间限制: 1000ms ...
- POJ 1163 The Triangle(经典问题教你彻底理解动归思想)
The Triangle Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 38195 Accepted: 22946 De ...
- POJ 1163 The Triangle 简单DP
看题传送门门:http://poj.org/problem?id=1163 困死了....QAQ 普通做法,从下往上,可得状态转移方程为: dp[i][j]= a[i][j] + max (dp[i+ ...
- poj 1163 The Triangle
The Triangle Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 43809 Accepted: 26430 De ...
- Poj 1163 The Triangle 之解题报告
Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 42232 Accepted: 25527 Description 7 3 ...
- poj 1163 The Triangle 搜索 难度:0
The Triangle Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 37931 Accepted: 22779 De ...
随机推荐
- sizeof和strlen在string类中的使用
字符串的sizeof和strlen 考虑下面的问题: char a[] = "abcdef"; char b[20] = "abcdef"; string s ...
- 解决: "E: 无法获得锁 /var/lib/dpkg/lock - open (11: 资源暂时不可用) ..."
解决: "E: 无法获得锁 /var/lib/dpkg/lock - open (11: 资源暂时不可用) E: 无法锁定管理目录(/var/lib/dpkg/),是否有其他进程正占用它?& ...
- 手把手搭建一套私有 npm 服务
手把手搭建一套私有 npm 服务 gnpm xnpm pnpm lnpm refs xgqfrms 2012-2020 www.cnblogs.com 发布文章使用:只允许注册用户才可以访问!
- React.memo All In One
React.memo All In One https://reactjs.org/docs/react-api.html#components React.memo const MyComponen ...
- SwiftUI render WKWebView
SwiftUI render WKWebView // // ContentView.swift // webview-app // // Created by 夏凌晨 on 2020/10/27. ...
- cookie all in one
cookie all in one credentials: "include" https://developers.google.com/web/updates/2015/03 ...
- pure CSS waterfall layout
pure CSS waterfall layout 纯 CSS 瀑布流布局 flex layout .container{} .item{} https://caniuse.com/?search=c ...
- 线上 S1 故障是什么, 线上 S1 故障, 运维故障分级, 运维, 故障分级, P1 级别故障, 故障, P1 , S1
线上 S1 故障是什么 线上 S1 故障, 运维故障分级, 运维, 故障分级, P1 级别故障, 故障, P1 , S1 故障复盘 https://time.geekbang.org/column/a ...
- Nodejs file path to url path
import * as path from 'path'; import * as url from 'url'; const savePath = path.join('public', 'imag ...
- JavaScript数据类型判断的四种方法
码文不易啊,转载请带上本文链接呀,感谢感谢 https://www.cnblogs.com/echoyya/p/14416375.html 本文分享了JavaScript类型判断的四种方法:typeo ...