03 2019 档案
摘要:闭包 注意到返回的函数在其定义内部引用了局部变量args,所以,当一个函数返回了一个函数后,其内部的局部变量还被新函数引用,所以,闭包用起来简单,实现起来可不容易。 另一个需要注意的问题是,返回的函数并没有立刻执行,而是直到调用了f()才执行。我们来看一个例子: 在上面的例子中,每次循环,都创建了一
阅读全文
摘要:0、求回文数 回数是指从左向右读和从右向左读都是一样的数,例如12321,909。请利用filter()筛选出回数: # 测试: 1、案例解释 a='python'b=a[::-1]print(b) #nohtypc=a[::-2]print(c) #nhy#从后往前数的话,最后一个位置为-1d=a
阅读全文
摘要:求结点对之间有负数的距离。限制条件:不允许有包含负权值的边组成的回路。 例子: 1.初始化 其中distance矩阵表示i,j两结点之间的距离。 path矩阵,以第一行为例,表示0->0值为n表示不可达,0->1值为0表示可由0到1. 2.i,j两结点经过0结点的情况 以此类推。 代码:
阅读全文
摘要:Maximum subarray problem The maximum subarray problem is the task of finding the contiguous subarray within a one-dimensional array, a[1...n], of numb
阅读全文
摘要:Integer Partition In number theory and combinatorics, a partition of a positive integer n, also called an integer partition, is a way of writing nas a
阅读全文
摘要:中文理解: 0-1背包问题:有一个贼在偷窃一家商店时,发现有n件物品,第i件物品价值vi元,重wi磅,此处vi与wi都是整数。他希望带走的东西越值钱越好,但他的背包中至多只能装下W磅的东西,W为一整数。应该带走哪几样东西?这个问题之所以称为0-1背包,是因为每件物品或被带走;或被留下;小偷不能只带走
阅读全文
摘要:Longest Increasing Subsequence The longest increasing subsequence problem is to find a subsequence of a given sequence in which the subsequence's elem
阅读全文
摘要:Levenshtein Distance The Levenshtein distance is a string metric for measuring the difference between two sequences. Informally, the Levenshtein dista
阅读全文
摘要:Longest common subsequence problem The longest common subsequence (LCS) problem is the problem of finding the longest subsequence common to all sequen
阅读全文
摘要:Staircase Problem There are n stairs, a person standing at the bottom wants to reach the top. The person can climb either 1 or 2 stairs at a time. Cou
阅读全文
摘要:Rain Terraces (Trapping Rain Water) Problem Given an array of non-negative integers representing terraces in an elevation map where the width of each
阅读全文
摘要:Unique Paths Problem A robot is located at the top-left corner of a m x n grid (marked 'Start' in the diagram below). The robot can only move either d
阅读全文
摘要:斐波那契数列:0 1 1 2 3 5 8 13 21... 给出一个n,求数组。 代码如下:
阅读全文
摘要:Jump Game The Problem Given an array of non-negative integers, you are initially positioned at the first index of the array. Each element in the array
阅读全文
摘要:Depth-First Search (DFS) Depth-first search (DFS) is an algorithm for traversing or searching tree or graph data structures. One starts at the root (s
阅读全文
摘要:Depth-first search (DFS) is an algorithm for traversing or searching tree or graph data structures. One starts at the root (selecting some arbitrary n
阅读全文
摘要:A recursive merge sort algorithm used to sort an array of 7 integer values. These are the steps a human would take to emulate merge sort (top-down). C
阅读全文
摘要:The rows of Pascal's triangle are conventionally enumerated starting with row n = 0 at the top (the 0th row). The entries in each row are numbered fro
阅读全文
摘要:The Tower of Hanoi (also called the Tower of Brahma or Lucas' Tower and sometimes pluralized) is a mathematical game or puzzle. It consists of three r
阅读全文
浙公网安备 33010602011771号