09 2017 档案
摘要:背包问题无疑是最经典的dp问题,其次就是关于字符串匹配问题,数组最长递增(减)序列长度等等。背包问题变体很多。以下内容多为摘抄。(from 崔添翼背包九讲) 动态规划问题实际上与备忘录式深搜有些类似。 1. 0-1背包 1.1 题目描述 题目: 有n个重量和价值分别为wi, vi的物品。从这些物品中
阅读全文
摘要:安装环境:Ubuntu 16.04lts 64位,gcc5.4 1.安装Cuda 1. 下载cuda toolkit。 下载cuda8.0 地址:https://developer.nvidia.com/cuda-downloads 版本选择:Operating System:Linux; Arch
阅读全文
摘要:题目: Given an unsorted array of integers, find the number of longest increasing subsequence. Example 1: Example 2: 题解: 首先解决最长的递增序列问题,最朴素的做法是深搜,以每一个数为开头
阅读全文
摘要:安装环境:Ubuntu 16.04lts 64位, gcc5.4 gpu1050ti,cuda8.0,cudnn5.1.10 1. 安装依赖库 2. 安装caffe 终端输入命令: 然后找到caffe文件夹,打开后会发现Makefile.config.example 文件, 这时候将Makefile
阅读全文
摘要:1. 每个C++都包含至少一个函数,其中一个必须为main函数,且 main 函数的返回类型必须为 int。 2. 函数定义包括:返回类型,函数名,形参列表,函数体 3. main 函数返回值用来指示状态,0表示成功,其他值含义由系统定义,通常用来表示错误类型。 4. 通过 echo 命令可以获得
阅读全文
摘要:摘自http://www.cplusplus.com 1. scanf 函数 Parameters format Whitespace character: the function will read and ignore any whitespace characters encountered
阅读全文
摘要:摘自《程序员代码面试指南》 题目: 给定数组 arr 和整数 num, 共返回有多少个⼦数组满⾜如下情况:max(arr[i...j]) - min(arr[i...j]) <= nummax(arr[i...j])表示⼦数组 arr[i...j]中的最⼤值,min(arr[i...j])表示⼦数组
阅读全文
摘要:单调栈 单调栈,就是一个栈,里面的元素满足一定的单调性。(多见于单调增/单调减) 1)新元素加入栈前,会在栈顶端把破坏栈单调性的元素都删除,直到栈为空或者栈满足单调性才能加入新元素。 2)单调栈是 O(n) 级的时间复杂度,所有元素只会进入栈一次,并且出栈后再也不会进栈。 3)单调栈可以找到元素向左
阅读全文
摘要:题目: Given a 2D binary matrix filled with 0's and 1's, find the largest rectangle containing only 1's and return its area. For example, given the follo
阅读全文
摘要:题目: Given n non-negative integers representing the histogram's bar height where the width of each bar is 1, find the area of largest rectangle in the
阅读全文
摘要:转自九章算法公众号 题目描述 给出包含n个整数的数组,你的任务是检查它是否可以通过修改至多一个元素变成非下降的。一个非下降的数组array对于所有的i(1<=i<n)满足array[i-1]<=array[i]。n属于区间[1,10000]。 样例1: ⅰ 输入: [4,2,3] ⅱ 输出: Tru
阅读全文
摘要:摘自http://www.cplusplus.com assert : macro 如果表达式值为0(即假),这时会向std::cerr设备发送一条信息,同时abort被调用,程序终止运行。 向std::cerr发送的信息内容取决与具体的库实现,但至少应包括以下内容:引起assert判断为错误的表达
阅读全文
摘要:■題目描述现在信用卡开展营销活动,持有我行信用卡客户推荐新户办卡,开卡成功后可获得积分奖励。规定每个客户最多可推荐两个新户且一个新户只能被推荐一次。但允许链接效应,即若客户A推荐了新户B,新户B推荐新户C,则客户同时属于A和B的推荐列表。简单起见,只考虑一个老客户A作起点推荐的情况。编程计算推荐新户
阅读全文
摘要:转载自九章算法(地址) 题目: 假设s是一个无限循环的字符串”abcdefghijklmnopqrstuvwxyz”,s就是一个”...zabcdefghijklmnopqrstuvwxyza...”这样的字符串,现在给你另外一个字符串p,求p中存在多少个截然不同的子串,使得它们也是s的子串。p只包
阅读全文
摘要:题目: 给定一个数组和滑动窗口的大小,请找出所有滑动窗口里的最大值。 输入 2 3 4 2 6 2 5 1 输出 4 4 6 6 6 5 题解: 在存入一个数字之前,首先要判断队列里已有数字是否小于待存入的数字。 1. 如果已有数字不大于待存入的数字,这些数字已不可能是滑动窗口的最大值,依次它们将会
阅读全文
摘要:汉诺塔游戏: 汉诺塔(Hanoi Tower),又称河内塔,源于印度一个古老传说。大梵天创造世界的时候做了三根金刚石柱子,在一根柱子上从下往上按照大小顺序摞着64片黄金圆盘。大梵天命令婆罗门把圆盘从下面开始按大小顺序重新摆放在另一根柱子上。并且规定,任何时候,在小圆盘上都不能放大圆盘,且在三根柱子之
阅读全文
摘要:题目: 一个栈中元素的类型为整型,现在想将该栈从顶到底按从大到小的顺序排序,只许申请一个栈,除此之外可以申请新的变量,但不能申请额外的数据结构。如何完成排序? 题解: 需要用到辅助栈。stack执行pop操作,弹出元素记为cur; 如果cur小于或等于assist的栈顶元素,则将cur直接压入ass
阅读全文
摘要:题目: 一个栈依次压入1、2、3、4、5,那么从栈顶到栈底分别为5、4、3、2、1。将这个栈转置后,从栈顶到栈底为1、2、3、4、5,也就是实现栈中元素的逆序。但是只能用递归函数来实现,不能用其他数据结构 题解: 需要两个递归函数:1. 将栈底元素返回并删除;2. 逆序一个栈 过程即为获取栈底元素,
阅读全文
摘要:题目: Implement the following operations of a queue using stacks. push(x) -- Push element x to the back of queue. pop() -- Removes the element from in f
阅读全文
摘要:题目: Design a stack that supports push, pop, top, and retrieving the minimum element in constant time. push(x) -- Push element x onto stack. pop() -- R
阅读全文
摘要:1. 魔法币 DESCRIPTION 小易准备去魔法王国采购魔法神器,购买魔法神器需要使用魔法币,但是小易现在一枚魔法币都没有,但是小易有两台魔法机器可以通过投入x(x可以为0)个魔法币产生更多的魔法币。魔法机器1:如果投入x个魔法币,魔法机器会将其变为2x+1个魔法币魔法机器2:如果投入x个魔法币
阅读全文
摘要:题目: Given a non-negative integer represented as a non-empty array of digits, plus one to the integer. You may assume the integer do not contain any le
阅读全文
摘要:题目: You are given an n x n 2D matrix representing an image. Rotate the image by 90 degrees (clockwise). Note:You have to rotate the image in-place, wh
阅读全文
摘要:题目: Determine if a Sudoku is valid, according to: Sudoku Puzzles - The Rules. The Sudoku board could be partially filled, where empty cells are filled
阅读全文
摘要:题目: The set [1,2,3,…,n] contains a total of n! unique permutations. By listing and labeling all of the permutations in order,We get the following sequ
阅读全文
摘要:题目: Given an array of integers, return indices of the two numbers such that they add up to a specific target. You may assume that each input would hav
阅读全文
摘要:题目: Given an unsorted array of integers, find the length of the longest consecutive elements sequence. For example,Given [100, 4, 200, 1, 3, 2],The lo
阅读全文
摘要:题目: Follow up for "Search in Rotated Sorted Array":What if duplicates are allowed? Would this affect the run-time complexity? How and why? Suppose an
阅读全文
摘要:题目: Suppose an array sorted in ascending order is rotated at some pivot unknown to you beforehand. (i.e., 0 1 2 4 5 6 7 might become 4 5 6 7 0 1 2). Y
阅读全文
摘要:题目: Follow up for "Remove Duplicates":What if duplicates are allowed at most twice? For example,Given sorted array nums = [1,1,1,2,2,3], Your function
阅读全文