03 2019 档案

摘要:闭包 注意到返回的函数在其定义内部引用了局部变量args,所以,当一个函数返回了一个函数后,其内部的局部变量还被新函数引用,所以,闭包用起来简单,实现起来可不容易。 另一个需要注意的问题是,返回的函数并没有立刻执行,而是直到调用了f()才执行。我们来看一个例子: 在上面的例子中,每次循环,都创建了一 阅读全文
posted @ 2019-03-28 22:11 Archer-Fang 阅读(137) 评论(0) 推荐(0)
摘要:0、求回文数 回数是指从左向右读和从右向左读都是一样的数,例如12321,909。请利用filter()筛选出回数: # 测试: 1、案例解释 a='python'b=a[::-1]print(b) #nohtypc=a[::-2]print(c) #nhy#从后往前数的话,最后一个位置为-1d=a 阅读全文
posted @ 2019-03-28 21:45 Archer-Fang 阅读(609) 评论(0) 推荐(0)
摘要:求结点对之间有负数的距离。限制条件:不允许有包含负权值的边组成的回路。 例子: 1.初始化 其中distance矩阵表示i,j两结点之间的距离。 path矩阵,以第一行为例,表示0->0值为n表示不可达,0->1值为0表示可由0到1. 2.i,j两结点经过0结点的情况 以此类推。 代码: 阅读全文
posted @ 2019-03-23 16:55 Archer-Fang 阅读(259) 评论(0) 推荐(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 阅读全文
posted @ 2019-03-19 13:30 Archer-Fang 阅读(176) 评论(0) 推荐(0)
摘要: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 阅读全文
posted @ 2019-03-19 12:26 Archer-Fang 阅读(675) 评论(0) 推荐(0)
摘要:中文理解: 0-1背包问题:有一个贼在偷窃一家商店时,发现有n件物品,第i件物品价值vi元,重wi磅,此处vi与wi都是整数。他希望带走的东西越值钱越好,但他的背包中至多只能装下W磅的东西,W为一整数。应该带走哪几样东西?这个问题之所以称为0-1背包,是因为每件物品或被带走;或被留下;小偷不能只带走 阅读全文
posted @ 2019-03-19 11:36 Archer-Fang 阅读(1291) 评论(0) 推荐(0)
摘要:Longest Increasing Subsequence The longest increasing subsequence problem is to find a subsequence of a given sequence in which the subsequence's elem 阅读全文
posted @ 2019-03-19 10:59 Archer-Fang 阅读(177) 评论(0) 推荐(0)
摘要:Levenshtein Distance The Levenshtein distance is a string metric for measuring the difference between two sequences. Informally, the Levenshtein dista 阅读全文
posted @ 2019-03-18 12:31 Archer-Fang 阅读(288) 评论(0) 推荐(0)
摘要:Longest common subsequence problem The longest common subsequence (LCS) problem is the problem of finding the longest subsequence common to all sequen 阅读全文
posted @ 2019-03-18 11:31 Archer-Fang 阅读(236) 评论(0) 推荐(0)
摘要: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 阅读全文
posted @ 2019-03-18 11:04 Archer-Fang 阅读(212) 评论(0) 推荐(0)
摘要:Rain Terraces (Trapping Rain Water) Problem Given an array of non-negative integers representing terraces in an elevation map where the width of each 阅读全文
posted @ 2019-03-15 11:51 Archer-Fang 阅读(243) 评论(0) 推荐(0)
摘要: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 阅读全文
posted @ 2019-03-15 10:58 Archer-Fang 阅读(188) 评论(0) 推荐(0)
摘要:斐波那契数列:0 1 1 2 3 5 8 13 21... 给出一个n,求数组。 代码如下: 阅读全文
posted @ 2019-03-15 10:42 Archer-Fang 阅读(117) 评论(0) 推荐(0)
摘要: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 阅读全文
posted @ 2019-03-14 13:51 Archer-Fang 阅读(316) 评论(0) 推荐(0)
摘要: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 阅读全文
posted @ 2019-03-14 12:40 Archer-Fang 阅读(136) 评论(0) 推荐(0)
摘要: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 阅读全文
posted @ 2019-03-14 11:32 Archer-Fang 阅读(145) 评论(0) 推荐(0)
摘要: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 阅读全文
posted @ 2019-03-14 10:53 Archer-Fang 阅读(313) 评论(0) 推荐(0)
摘要: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 阅读全文
posted @ 2019-03-11 13:59 Archer-Fang 阅读(668) 评论(0) 推荐(0)
摘要: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 阅读全文
posted @ 2019-03-11 13:11 Archer-Fang 阅读(267) 评论(0) 推荐(0)