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 ...
随机推荐
- git merge bug
git merge bug 本地分支 dev commit 后, 直接 pull 远程 dev 分支, 导致远程 dev 分支 merge 到本地 dev 分支了, 取消本次 merge 操作? Re ...
- web components in action
web components in action web components css-doodle.js https://alligator.io/workflow/ https://d33wubr ...
- NGINX configure auto generator
NGINX configure auto generator The easiest way to configure a performant, secure, and stable NGINX s ...
- node.js delete directory & file system
node.js delete directory & file system delete a not empty directory https://nodejs.org/api/fs.ht ...
- how to auto open a url in the browser by using terminal
how to auto open a url in the browser by using terminal Linux / MacOS # bash / zsh $ open http://loc ...
- h5 localStorage和sessionStorage浏览器数据缓存
sessionStorage 会话数据,localStorage 没有过期时间 两个的API基本都一样的 基本的使用 // 保存一个数据 sessionStorage.setItem('key', ' ...
- 开源OA办公系统的“应用市场”,能够为协同办公开拓什么样的“前路”?
在我们的日常生活中,应用市场这个词,总是与智能手机划上等号,不管使用的是iPhone还是安卓,总会接触到手机上的APP应用市场,我们可以在应用市场中,选择自己所需要的APP应用软件,下载使用后,可以让 ...
- Anno&Viper -分布式锁服务端怎么实现
1.Anno简介 Anno是一个微服务框架引擎.入门简单.安全.稳定.高可用.全平台可监控.依赖第三方框架少.底层通讯RPC(Remote Procedure Call)采用稳定可靠经过无数成功项目验 ...
- 微信小程序:picker组件实现下拉框效果
一.wxml中代码 <view class="in_order_Param"> <text>状态:</text> ...
- 后端程序员之路 57、go json
go自带json处理库,位于encoding/json,里面的test很具参考意义,特别是example_test.go json - The Go Programming Languagehttps ...