一、题目

  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 【动态规划】的更多相关文章

  1. POJ 1163 The Triangle(简单动态规划)

    http://poj.org/problem?id=1163 The Triangle Time Limit: 1000MS   Memory Limit: 10000K Total Submissi ...

  2. poj 1163 The Triangle &amp;poj 3176 Cow Bowling (dp)

    id=1163">链接:poj 1163 题意:输入一个n层的三角形.第i层有i个数,求从第1层到第n层的全部路线中.权值之和最大的路线. 规定:第i层的某个数仅仅能连线走到第i+1层 ...

  3. POJ 1163 The Triangle【dp+杨辉三角加强版(递归)】

    The Triangle Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 49955   Accepted: 30177 De ...

  4. OpenJudge/Poj 1163 The Triangle

    1.链接地址: http://bailian.openjudge.cn/practice/1163 http://poj.org/problem?id=1163 2.题目: 总时间限制: 1000ms ...

  5. POJ 1163 The Triangle(经典问题教你彻底理解动归思想)

    The Triangle Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 38195   Accepted: 22946 De ...

  6. POJ 1163 The Triangle 简单DP

    看题传送门门:http://poj.org/problem?id=1163 困死了....QAQ 普通做法,从下往上,可得状态转移方程为: dp[i][j]= a[i][j] + max (dp[i+ ...

  7. poj 1163 The Triangle

    The Triangle Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 43809   Accepted: 26430 De ...

  8. Poj 1163 The Triangle 之解题报告

    Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 42232   Accepted: 25527 Description 7 3 ...

  9. poj 1163 The Triangle 搜索 难度:0

    The Triangle Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 37931   Accepted: 22779 De ...

随机推荐

  1. 使用SignTool对软件安装包进行数字签名(二)--进行数字签名

    四.使用signcode.exe为安装程序.库或cab包签名 1.运行signcode.exe. 2.点击"下一步",选择需要签名的文件(安装程序.库或cab包). 3.点击&qu ...

  2. 1.初识Redis

    作者 微信:tangy8080 电子邮箱:914661180@qq.com 更新时间:2019-08-14 20:35:36 星期三 欢迎您订阅和分享我的订阅号,订阅号内会不定期分享一些我自己学习过程 ...

  3. np.random.randint()的返回值

    返回的是数组而非int 比如返回x,y 为[1][2] 而非1,2 容易在只有一维一列时没有意识到 其他函数的返回值也要注意

  4. Axios 取消 Ajax 请求

    Axios 取消 Ajax 请求 Axios XMLHttpRequest https://caniuse.com/?search=XMLHttpRequest https://developer.m ...

  5. X-Frame-Options & iframe & CORS

    X-Frame-Options & iframe & CORS https://github.com/xgqfrms/FEIQA/issues/23 X-Frame-Options i ...

  6. Ethical Hacking Tutorials

    Ethical Hacking Tutorials Free Ethical Hacking Tutorials https://www.guru99.com/ethical-hacking-tuto ...

  7. JavaScript Best Practice

    JavaScript Best Practice Clean, maintainable, execute code

  8. window resize & resize observer

    window resize & resize observer https://developer.mozilla.org/en-US/docs/Web/API/Window/resize_e ...

  9. js & for & for of & for in & forEach, break

    js & for & for of & for in & forEach, break js for break https://stackoverflow.com/q ...

  10. 以NGK 呼叫河马为例分析智能合约漏洞在哪?

    合约交易是指买方和卖方根据约定,在未来某一时刻,以指定价格接受某一资产的协议. 合约是买卖双方之间权利义务的表现形式.合约交易是一种金融衍生工具,与现货市场相比,用户通过判断期货合约交易的涨跌,选择买 ...