摘要: 11.1 动态规划的递归写法和逆推写法 动态规划没有固定的写法、极其灵活,常常需要具体问题具体分析。 11.1.1 什么是动态规划 动态规划将一个复杂的问题分解成若干个子问题,通过综合子问题的最优解来得到原问题的最优解。 11.1.2 动态规划的递归写法 如下是斐波那契数列的常规写法 int F(i 阅读全文
posted @ 2020-02-10 23:39 程序员小应 阅读(224) 评论(0) 推荐(0) 编辑
摘要: 10.3 图的遍历 PAT A1013 Battle Over Cities (25分) It is vitally important to have all the cities connected by highways in a war. If a city is occupied by t 阅读全文
posted @ 2020-02-09 16:48 程序员小应 阅读(193) 评论(0) 推荐(0) 编辑
摘要: 10.1 图的定义和相关术语 图由顶点和边组成,每条边的两端都必须是图的两个顶点。而记号G(V,E)表示图G的顶点集为V、边集为E。 一般来说,图可分为有向图和无向图。有向图的所有边都有方向,即确定了顶点到顶点的一个指向;而无向图的所有边都是双向的,即无向边所连接的两个顶点可以互相到达。 10.2  阅读全文
posted @ 2020-02-09 14:50 程序员小应 阅读(254) 评论(0) 推荐(0) 编辑
摘要: 9.2 二叉树的遍历 PAT A1020 Tree Traversals (25分) Suppose that all the keys in a binary tree are distinct positive integers. Given the postorder and inorder 阅读全文
posted @ 2020-02-07 18:04 程序员小应 阅读(171) 评论(0) 推荐(0) 编辑
摘要: 9.1 树与二叉树 9.1.1 树的定义与性质 数据结构中把树枝分叉处、树叶、树根抽象为结点,其中树根抽象为根结点,且对一棵树来说最多存在一个根节点;把树叶概括为叶子结点,且叶子结点不再延伸出新的结点;把茎干和树枝统一抽象为边,且一条边只用来连接两个结点。 下面给出几个比较实用的概念和性质: ① 空 阅读全文
posted @ 2020-02-06 18:20 程序员小应 阅读(194) 评论(0) 推荐(0) 编辑
摘要: 8.1 深度优先搜索(DFS) PAT A1103 Integer Factorization (30分) The K−P factorization of a positive integer N is to write N as the sum of the P-th power of K po 阅读全文
posted @ 2020-02-05 11:05 程序员小应 阅读(197) 评论(0) 推荐(0) 编辑
摘要: 8.1 深度优先搜索(DFS) 深度优先搜索会走遍所有路径,并且每次走到死胡同就代表一条完整路径的形成。这就是说,深度优先搜索是一种枚举所有完整路径以遍历所有情况的搜索方法。 例子(背包问题): 有n件物品,每件物品的重量w[i],价值为c[i]。现在需要选出若干件物品放入一个容量为V的背包中,使得 阅读全文
posted @ 2020-02-05 09:32 程序员小应 阅读(103) 评论(0) 推荐(0) 编辑
摘要: PAT A1051 Pop Sequence (25分) Given a stack which can keep M numbers at most. Push N numbers in the order of 1, 2, 3, ..., N and pop randomly. You are 阅读全文
posted @ 2020-02-04 23:00 程序员小应 阅读(163) 评论(0) 推荐(0) 编辑
摘要: 6.1 vector的常见用法详解 PAT A1039 Course List for Student (25分) Zhejiang University has 40000 students and provides 2500 courses. Now given the student name 阅读全文
posted @ 2020-02-02 17:20 程序员小应 阅读(210) 评论(0) 推荐(0) 编辑
摘要: PAT A1069/B1019 The Black Hole of Numbers (20分) For any 4-digit integer except the ones with all the digits being the same, if we sort the digits in n 阅读全文
posted @ 2020-02-01 16:36 程序员小应 阅读(264) 评论(0) 推荐(0) 编辑