- 博客(38)
- 收藏
- 关注
原创 【算法概论】习题8.12证明题
《算法概论》习题8.12证明题题目k-生成树问题是这样一个问题: 输入:无向图G=(V,E) 输出:G的一个生成树,其中所有节点度数都不超过k——如果该树存在。 请证明对任意k>=2: (a)k-生成树问题是一个搜索问题。 (b)k-生成树问题是NP-完全的。解答(a)一个搜索问题的定义是:任何可能解的正确性都能快速地被验证,而快速指的是能够在多项式时间内被验证。证明k-生
2017-07-03 21:18:11
746
原创 【算法概论】习题8.3答案
【算法概论】习题8.3答案题目8.3 吝啬SAT问题是这样的:给定一组子句(每个子句都是其中文字的析取)和整数k,求一个最多有k个变量为true的满足赋值——如果该赋值存在。证明吝啬SAT是NP-完全问题。解答要证明一个问题是NP-完全问题,需要证明以下两点: 1. 它是一个NP问题,且 2. 其他属于NP的问题都可归约成它。第一点的证明很简单:为了找到一个最多有k个变量为t
2017-07-03 20:44:23
1183
原创 [leetcode] 91. Decode Ways
91. Decode Ways A message containing letters from A-Z is being encoded to numbers using the following mapping: ‘A’ -> 1 ‘B’ -> 2… … ‘Z’ -> 26 Given an encoded message containing digits,
2017-06-26 11:52:01
755
原创 [leetcode] 85. Maximal Rectangle
Maximal Rectangle 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 following matrix: 1 0 1 0 0 1 0 1 1 1
2017-06-26 11:33:02
365
原创 [Leetcode] 57. Insert Interval
Insert Interval Given a set of non-overlapping intervals, insert a new interval into the intervals(merge if necessary). You may assume that the intervals were initially sorted according to their star
2017-06-26 10:49:53
418
原创 [Leetcode] 123. Best Time to Buy and Sell Stock III
123. Best Time to Buy and Sell Stock IIISay you have an array for which the i-th element is the price of a given stock on day i. Design an algorithm to find the maximum profit. You may complete at mos
2017-06-04 23:25:16
539
原创 [Leetcode]122. Best Time to Buy and Sell Stock II
122. Best Time to Buy and Sell Stock IISay you have an array for which the i-th element is the price of a given stock on day i.Design an algorithm to find the maximum profit. You may complete as many t
2017-06-04 22:36:16
714
原创 [Leetcode] 121. Best Time to Buy and Sell Stock
121. Best Time to Buy and Sell StockSay you have an array for which the i-th element is the price of a given stock on day i. if you were only permitted to complete at most one transaction(ie, buy one
2017-06-04 21:56:06
505
原创 [leetcode] Median of Two Sorted Arrays
[4] Median of Two Sorted Arrays There are tow sorted arrays nums1 and nums2 of size m and n respectively. Find the median of the two sorted arrays. The overall run time complexity should be O(log(m+n
2017-06-03 12:05:54
653
原创 [Leetcode] 41. First Missing Positive
41. First Missing PositiveGiven an unsorted integer array, find the first missing positive integer.For example, Given [1,2,0] return 3, and [3,4,-1,1] return 2.Your algorithm should run in O(n) time
2017-05-14 21:47:13
515
原创 [leetcode] 76. Minimum Window Substring
76. Minimum Window Substring题目:Given a string S and a string T, find the minimum window in S which will contain all the characters in T in complexity O(n).For example, S = “ADOBECODEBANC” T = “ABC”
2017-05-08 09:52:41
469
原创 [leetcode] 567. Permutation in String
567. Permutation in StringGiven two strings s1 and s2, write a function to return true if s2 contains the permutation of s1. In other words, one of the first string’s permutations is the substring of t
2017-05-07 20:52:32
3211
原创 [leetcode] 91. Decode Ways
91. Decode Ways题目A message containing letters from A-Z is being encoded to numbers using the following mapping:‘A’ -> 1 ‘B’ -> 2 … ‘Z’ -> 26 Given an encoded message containing digits, determine th
2017-04-23 19:15:50
346
原创 [lletcode]Word Break
Word Break题目:Given a non-empty string s and a dictionary wordDict containing a list of non-empty words, determine if s can be segmented into a space-separated sequence of one or more dictionary words.
2017-04-23 18:46:49
433
原创 [leetcode] 64. Minimum Path Sum Add to List
64. Minimum Path Sum Add to ListGiven a m x n grid filled with non-negative numbers, find a path from top left to bottom right which minimizes the sum of all numbers along its path.Note: You can only m
2017-04-09 22:53:09
504
原创 【Leetcode】Jump Game
55. Jump GameGiven an array of non-negative integers, you are initially positioned at the first index of the array.Each element in the array represents your maximum jump length at that position.Determi
2017-04-02 23:06:08
401
原创 【leetcode】406. Queue Reconstruction by Height
406. Queue Reconstruction by Height题目Suppose you have a random list of people standing in a queue. Each person is described by a pair of integers (h, k), where h is the height of the person and k is th
2017-03-26 21:01:07
398
原创 [leetcode] 491. Increasing Subsequences
Given an integer array, your task is to find all the different possible increasing subsequences of the given array, and the length of an increasing subsequence should be at least 2 .Example: Input: [4
2017-03-19 17:22:14
1624
原创 【leetcode】133. Clone Graph
133. Clone Graph这道题目的意思是:对一个无向图进行深拷贝,即需要申请一个新的空间,并将原来的无向图中的节点及相关信息拷贝到这个新的空间。因此解题思路其实就是对这个无向图进行遍历,并且一边遍历一边深拷贝即可。对于无向图的遍历,可以采用深度遍历(DFS)和广度遍历(BFS)完成,两者的时间复杂度和空间复杂度都是O(n)。方法一:深度遍历(DFS)// Definition for un
2017-03-12 21:02:51
654
原创 【leetcode】215. Kth Largest Element in an Array
【leetcode】215. Kth Largest Element in an ArrayFind the kth largest element in an unsorted array. Note that it is the kth largest element in the sorted order, not the kth distinct element.For example,
2017-03-06 01:06:18
456
原创 【机器学习】判别模型vs生成模型
判别模型vs生成模型条件概率分布p(y|x)从概率的角度来看监督学习的话,其实就是从数据集中学习条件概率分布p(y|x)。其中,x∈Rnx \in R^n表示n维数据特征,y∈Ry \in R表示数据对应的类别标签。给定一个x,模型计算出x属于各个类别标签y的概率p(y|x),然后判定x的预测标签为p(y|x)最大的y标签。比如,现在的一个问题为判定一个动物是汪星人还是喵星人。这个问题可以表示为x=
2017-02-28 22:39:15
775
原创 【机器学习】文本数据简单向量化
一个文本数据指的是一篇文章,或者一段话,或者一句话。这个文本数据通常称为document,或者text。我们平常的文本都是以人的表达方式展现的,是一个流数据,时间序列数据。我们如果要用计算机对文本数据进行处理,就必须将文本数据表示为计算机能理解的方式。这篇博客就讲解给定一个已经分词、去除停用词后的文本数据集,如何将其向量化的方法。one-hot表示法one-hot表示法先将文本数据集中不重复的单词提
2017-02-27 22:13:40
13593
原创 【机器学习】KNN(k-Nearest Neighbor)算法
K近邻(k-Nearest Neighbor, 简称KNN)算法是一种非常简单的机器学习监督算法。它的主要思想是:给定一个测试数据,如果离它最近的K个训练数据大多都属于某一个类别,则认为该测试数据也属于这个类别。以下图为例,图中的绿色点表示测试数据,现在我们需要判断这个点应该是红色三角形还是蓝色正方形。按照上述思想,如果K取3,则离绿色点最近的点中有两个是红色三角形,一个是蓝色正方形,因此KNN判断
2017-02-27 20:47:32
11670
原创 [leetcode] 1. twoSum; 167. Two Sum II - Input array is sorted; 15. threeSum; 16. 3Sum Closest; 18. 4
[leetcode] 1. twoSum; 167. Two Sum II - Input array is sorted; 15. threeSum; 16. 3Sum Closest; 18. 4Sum这篇文章涉及到leetcode中求和的相关题目。1. twoSum [Easy]Given an array of integers, return indices of the two numb
2017-02-26 15:35:25
621
原创 数据结构-平衡二叉树(AVL Tree)
在 数据结构-二叉树(binary tree)-二叉查找树(binary search tree) 的最后面,提到过在二叉树中增加或者删除节点,可能导致树的左右子树高度相差很多,即导致树不平衡。为了解决这个问题,规定在插入或者删除节点的时候,必须保证每一个节点的左右子树的高度差的绝对值不超过1,| height(left) - height(right) | <= 1。这样的二叉树称为平衡二叉树
2016-05-15 20:43:29
7080
原创 数据结构-堆(heap)
堆(heap)也被称为优先队列(priority queue)。队列中允许的操作是先进先出(FIFO),在队尾插入元素,在队头取出元素。而堆也是一样,在堆底插入元素,在堆顶取出元素,但是堆中元素的排列不是按照到来的先后顺序,而是按照一定的优先顺序排列的。这个优先顺序可以是元素的大小或者其他规则。
2016-05-15 20:00:44
52536
6
原创 数据结构-前序遍历、中序遍历、后序遍历、层级遍历(递归、非递归)
二叉树的遍历是一个非常基础又重要的内容。遍历就是访问二叉树中的每一个节点,并且每个节点只访问一次。二叉树的遍历分为前序遍历、中序遍历、后序遍历和层级遍历。
2016-05-13 15:42:29
3432
原创 [sicily] 1021. Couples
1021. CouplesConstraintsTime Limit: 1 secs, Memory Limit: 32 MBDescriptionN couples are standing in a circle, numbered consecutively clockwise from 1 to 2N. Husband and wife do not always stand toget
2016-05-12 20:18:45
397
原创 [sicily] 1020. Big Integer
1020. Big IntegerConstraintsTime Limit: 1 secs, Memory Limit: 32 MBDescriptionLong long ago, there was a super computer that could deal with VeryLongIntegers(no VeryLongInteger will be negative). Do yo
2016-05-12 20:08:15
377
原创 [sicily]1002. Anti-prime Sequences
题目解析:注意在判断一个d anti-prime sequence时,需要判断连续2,3…,d个数字的和是否都是一个合数!解题思路 深度搜索:从第一个数字开始,不断向序列中加入新的数字,判断加入的数字是否能够组成一个d-anti-prime sequence。如果可以则继续增加新元素,否则弹出这个元素,尝试加入下一个数字。主要的解题思路已经知道可以采用深度搜索了,但是还需要解决一个问题,就是如何判
2016-05-12 15:27:14
705
原创 [sicily] 1001. Alphacode
题目大意: 假设有一规则:’A’ 设为1,’B’设为2,以此类推, ‘Z’设为26。按照这个规则给一串英文字母编码,将会得到一个数字码。现在给定这个数字码,求出可以解码出多少种不同的英文字母。解题思路 动态规划:由于总共有26个英文字母,那么数字码可能取1~26。那么对于每一个数字,这个数字可以单独解码,也可以与其前面一个数字一起解码。则得到的解码规则如下: 以下每种情况,初始时,结果 =
2016-05-11 21:26:54
604
原创 数据结构-二叉树(binary tree)-二叉查找树(binary search tree)
二叉树(binary)二叉树就是节点的度不大于2的树,即树中每个节点的子节点最多只有两个。每个节点的子节点分为左子节点和右子节点,并且左右子节点的顺序不能改变。1. 二叉树分类二叉树分为满二叉树、完全二叉树和完美二叉树。
2016-05-10 15:30:13
2326
1
原创 数据结构-队列(queue)
队列(queue)是一种采用先进先出(FIFO)策略的抽象数据结构,它的想法来自于生活中排队的策略。顾客在付款结账的时候,按照到来的先后顺序排队结账,先来的顾客先结账,后来的顾客后结账。队列实现同栈的实现一样,队列的实现也有数组实现和链表实现两种方式。
2016-05-09 16:51:40
47043
5
原创 数据结构:链表(linked-list)
链表分为单向链表(Singly linked lis)、双向链表(Doubly linked list)、循环链表(Circular Linked list)。
2016-05-09 11:09:09
53459
8
转载 [sicily] 1003. hit or miss
#include #include using namespace std;int main() { int n; while(cin >> n) { for (int i = 0; i < n; ++i) { int numOfPlayer; cin >> numOfPlayer;
2015-05-29 18:18:07
484
原创 MinGW编译portaudio,win7
本篇博客介绍如何在win7系统下使用MinGW和msys编译portaudio。废话少说,直接进入主题:1. 下载和安装MinGW和msys 下载mingw-get-setup.exe,下载完成后使用mingw-get-setup安装MinGW和msys。 选择安装路径,并记住这个路径,一直点击【continue】 按照需要选择安装的软件,在这里我们选择第一个,第二个,第四个,第五个。然后
2015-03-10 13:31:59
1783
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人