一、题目

  The Triangle

二、分析

  动态规划入门题。

  状态转移方程$$DP[i][j] = A[i][j] + max(DP[i-1][j], DP[i][j])$$

三、AC代码

  1. 1 #include <cstdio>
  2. 2 #include <cstring>
  3. 3 #include <iostream>
  4. 4 #include <algorithm>
  5. 5 #include <vector>
  6. 6 #include <cmath>
  7. 7
  8. 8 using namespace std;
  9. 9 #define ll long long
  10. 10 #define Min(a,b) ((a)>(b)?(b):(a))
  11. 11 #define Max(a,b) ((a)>(b)?(a):(b))
  12. 12 const int MAXN = 100;
  13. 13 int A[MAXN + 13][MAXN + 13];
  14. 14 int Ans[2][MAXN + 13];
  15. 15
  16. 16 int main()
  17. 17 {
  18. 18 int N;
  19. 19 while(scanf("%d", &N) != EOF) {
  20. 20 memset(A, 0, sizeof(A));
  21. 21 memset(Ans, 0, sizeof(Ans));
  22. 22 for(int i = 1; i <= N; i++) {
  23. 23 for(int j = 1; j <= i; j++) {
  24. 24 scanf("%d", &A[i][j]);
  25. 25 }
  26. 26 }
  27. 27 for(int i = 1; i <= N; i++) {
  28. 28 for(int j = 1; j <= i; j++) {
  29. 29 Ans[i&1][j] = A[i][j] + Max(Ans[(i-1)&1][j-1], Ans[(i-1)&1][j]);
  30. 30 }
  31. 31 }
  32. 32 int ans = 0;
  33. 33 for(int i = 1; i <= N; i++) {
  34. 34 ans = Max(ans, Ans[N&1][i]);
  35. 35 }
  36. 36 printf("%d\n", ans);
  37. 37 }
  38. 38 return 0;
  39. 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. 关于优先队列的总结II

    优先队列这个数据结构还是很有用的,可以帮我们解决很多棘手的排序的问题,所以再来细细看一下, priority_queue<Type, Container, Functional> Type ...

  2. PWA All In One

    PWA All In One chrome://apps/ PWA Progressive Web App 可安装,添加到主屏 离线使用 轻量,快速 基于 Web 技术一套代码多端复用(移动端,桌面端 ...

  3. WebSocket All In One

    WebSocket All In One WebSocket heartbeat WebSocket 心跳检测 ping pong refs xgqfrms 2012-2020 www.cnblogs ...

  4. Professional JavaScript for Web Developers 4th Edition

    Professional JavaScript for Web Developers 4th Edition learning notes / 学习笔记 https://github.com/xgqf ...

  5. JavaScript console.log Questions All In One

    JavaScript console.log Questions All In One "use strict"; /** * * @author xgqfrms * @licen ...

  6. js in depth & prototype & __proto__

    js in depth & prototype & proto 实例的 proto 与 父类的 prototype,同时指向 父类的构造函数: https://hackernoon.c ...

  7. 人物传记Kyle Tedford:数据环境生变,银行大数据风控怎么办?

    数据是金融业务的基石,监管集中清查大数据公司,很多东西在发生根本性改变,资金方做"甩手掌柜"的好日子不会重现.那些缺乏自主风控能力的金融机构,在未来的行业竞争中,恐无以立足了.近日 ...

  8. Java中print、printf、println的区别

    Java中print.printf.println的区别 区别 print:标准输出,但不换行,不可以空参: println:标准输出,但会自动换行,可以空参,可以看做:println()相当于pri ...

  9. 链表、栈、队列、KMP相关知识点

    链表.栈与队列.kmp; 数组模拟单链表: 用的最多的是邻接表--就是多个单链表: 作用:存储树与图 需要明确相关定义: 为什么需要使用数组模拟链表 比使用结构体 或者类来说 速度更快 代码简洁 算法 ...

  10. Matplotlib 图表绘制工具学习笔记

    import numpy as np import matplotlib.pyplot as plt import pandas as pd arr1 = np.random.rand(10)#一维数 ...