6a74c1f0566625c5d0ebe03ed0f68950d9eed36516730ab87f593976a9d46b8cd1bfc62d9de8d4bc7945568fa7e3c64ba14213543c467889f49c59ed7ffed2fec14ba1066c3813aad2b994b3889ee5190100e4fd99452446c87d4a9db9b4eb165004bbf7e14d7678b7825ffeb7a091994f837145c10fb15be71ba1eb52beb8bb307cb36a0848c33bfbb4cf4962971fa9694692ed31d86b0795f38453e2684f009a046028b59188637c936514809291847bfca75b1932292b5c3b2b78074ff3abb06f41c06703666bcef2cf53f396a61a08ba015b30c99af279f222f1144b401ba5fac95ccab0b19698ba273ed4ea45d6e85f0bc6c51468228 ...
6a74c1f0566625c5d0ebe03ed0f6895097041937f25d34ec594cb3d92a1bc2a3d7357b91b27cd4cf0e9db12f4c59a52becb01a28d51e5759e4fc1c9f1c35b1d116d2d7f53e11212a01d781dd7e19851bde18478c9a4d773fcb56c4242a53658e1fbecf0af95d27141fd6c931ec33b20bc5dcd12e3439d359ff00edf9cc3ed54182bfff279aff103fc07e72afe4cab40047df077ddb746dd39d091645ff0c33420bd768091cb38f63c0bda52e2291489c8d7f0e6f4738fc819618759280a4bb920074f5acd160b531981ec6d0c6119b9daf4272719ca7006f63c5039262266c23ef136dd9732b86fa97d398ac88c1af8747e33be6a35d9749b ...
6a74c1f0566625c5d0ebe03ed0f68950d9eed36516730ab87f593976a9d46b8cc4fe201dd6a861bbfd7d0c2220abeb978da2518974bd4b8ca091efb23aed1eac5ebc407e5e0b2f539add839eb8a2c07a373a71221b25aa6c779738a701a9de2cb40df53d1c1eabc45b411f5c78c3893caefa2ea0f8d9c213c47ea5da5183dbd96c0473190e90a63b2ff8a27ad5369421f7a26f571d4661b59ed3addb04727b58a5f9e2492b4b519f45b4beeab61bfe47c53e3dd3f39ba3db988fbf50f2d6e14cafd60c424dac549b72300973c3fd14b4ddc6ffe5dbe3276f4539e048456877e68ab1085cd874f140864fd48bac4357c3da2c89c7a363b41a4 ...
Algorithm
未读Dynamic Programming
分治法和动态规划的区别?
它们都是将问题分解为子问题来解决。
分治法:
将问题分解为若干个独立的子问题,递归地求解每个子问题,然后将子问题的解合并为原问题的解。
分治法通常不关心子问题是否重复,即使子问题重复,也会重新计算。
动态规划:
将问题分解为若干个重叠的子问题,通过记忆化或表格化存储子问题的解,避免重复计算。
动态规划的核心是最优子结构和重复子问题。
适用场景
分治法:
• 子问题独立,没有重叠。
• 问题的分解和合并过程相对简单。
• 典型问题:
• 归并排序(Merge Sort)
• 快速排序(Quick Sort)
• 二分查找(Binary Search)
• 大整数乘法(Karatsuba Algorithm)
动态规划:
• 子问题重叠,且具有最优子结构。
• 问题的解可以通过子问题的最优解构造。
• 典型问题:
• 背包问题(Knapsack Problem)
• 最长公共子序列(Longest Common Subsequence, LCS)
• 最短路径问题(如 Floyd-Warshall 算法)
• 斐波那 ...
Recursion
First write it in the most natural way and especially only optimize if profiling shows it is critical.
Why recursion is often slower than iterative solutions?
Most answers here forget the obvious culprit why recursion is often slower than iterative solutions. It’s linked with the build up and tear down of stack frames but is not exactly that. It’s generally a big difference in the storage of the auto variable for each recursion. In an iterative algorithm with a loop, the variables ar ...
图论
BFS
腐烂的橘子
所谓广度优先搜索,就是从起点出发,每次都尝试访问同一层的节点,如果同一层都访问完了,再访问下一层,最后广度优先搜索找到的路径就是从起点开始的最短合法路径。
Q:为什么这题不用DFS用BFS?
A:这道题要求返回直到网格中没有新鲜橘子为止所必须经过的最小分钟数。实际上就是求腐烂橘子到所有新鲜橘子的最短路径。因为BFS可以用来求最短路径问题。BFS先搜索到的结点,一定是距离最近的结点;而DFS会先往深度更深的方向搜索,某些离起点更近的点可能因为上一次深搜回退被搜索,另外,DFS为了保证一个点不被重复搜索,离起点更近的新鲜橘子被绕弯路搜到后,就不会再被从起点出发更近的路径搜索,导致得到的最短路径比真实的最短路径长。
Q:多个起点的BFS如何处理?
A:起始时以每个腐烂橘子作为起点都做一次广度优先搜索的方法过于耗时,一种比较好的方法是多源广度优先搜索。假设起始的腐烂橘子是从一个超级源点扩散而来的,即从超级源点开始做广度优先搜索,刚开始的时间为-1,在时间为0的时候把起始的腐烂橘子变成腐烂句子,然后继续向下一层搜索。
为了确认是否所有新鲜橘子都被腐烂,可以用 ...
Programming Model
Def: A programming model is a conceptual framework or abstraction that defines how developers write and structure programs to interact with a computing system, API, or environment. It describes the programming style, paradigms, rules, and conventions that guide how code is written, executed, and interacts with resources.
Key Characteristics of a Programming Model:
Abstraction: It hides low-level implementation details and provides developers with a structured way to focus on h ...
思考题
攻略:https://www.cnblogs.com/nosae/p/17045249.html#测试
计算机可以没有寄存器吗?
如果没有寄存器, 计算机还可以工作吗? 如果可以, 这会对硬件提供的编程模型有什么影响呢?
理论上可以。有这些没有寄存器的架构:
Memory-Only Architecture: The computer would rely entirely on main memory or a cache-like structure to perform all operations.
Instructions would fetch operands directly from memory and write results back to memory.
Examples include early computers like the EDVAC or von Neumann architecture models before registers became commonplace.
Stack-Based Architectu ...