算法
文章平均质量分 64
qq379548839
这个作者很懒,什么都没留下…
展开
-
康托展开
前一阵人工智能课需要写一个八数码的题,其中用到了康托展开。 但当时是直接使用的公式,并没有仔细阅读具体的原理。 所以,今天整理一下。简介康托展开是全排列到自然数的双射,常用于对全排列的哈希。 康托展开实质是表示的是当前排列在全排列中的位置。公式n个数字排列的康托展开公式: 其中,ai表示第i位数字在当前集合是第ai小的数字。逆过程初始化集合Cn为n个数字的全集,Xn=X。Xi mod (原创 2016-10-14 14:56:31 · 297 阅读 · 0 评论 -
363. Max Sum of Rectangle No Larger Than K[hard]
题目: Given a non-empty 2D matrix matrix and an integer k, find the max sum of a rectangle in the matrix such that its sum is no larger than k.Example: Given matrix = [ [1, 0, 1], [0, -2, 3] ]原创 2016-11-27 21:05:43 · 439 阅读 · 0 评论 -
NP完全问题的归约-碰撞集(HITTING SET)
原题: 在碰撞集(HITTING SET)问题中,给定一组集合{S1, S2, S3, …, Sn}和预算b,我们希望求一个与所有Si相交且规模不超过b的集合H(H与所有Si相交不为空)。证明: (1)hitting set问题是NP问题 只需要验证H的大小是否不超过b,以及验证H与Si的交不为空。 时间复杂度O(nHS)。 所以,hitting set问题为NP问题。 (2)所有问题可原创 2016-11-27 11:48:51 · 4589 阅读 · 0 评论 -
Leetcode 96. Unique Binary Search Trees[medium]
题目: Given n, how many structurally unique BST’s (binary search trees) that store values 1…n?For example, Given n = 3, there are a total of 5 unique BST’s.1 3 3 2 1 \原创 2016-11-27 19:57:06 · 243 阅读 · 0 评论 -
POJ 1463 Strategic game
题目: Strategic game Time Limit: 2000MS Memory Limit: 10000K Total Submissions: 8051 Accepted: 3746 DescriptionBob enjoys playing computer games, especially strategic games, but sometimes he原创 2016-12-13 21:48:27 · 322 阅读 · 0 评论 -
Leetcode 416. Partition Equal Subset Sum[medium]
题目: Given a non-empty array containing only positive integers, find if the array can be partitioned into two subsets such that the sum of elements in both subsets is equal.Note: Each of the array ele原创 2016-12-13 21:42:34 · 335 阅读 · 0 评论 -
Leetcode 321. Create Maximum Number[hard]
题目: Given two arrays of length m and n with digits 0-9 representing two numbers. Create the maximum number of length k <= m + n from digits of the two. The relative order of the digits from the same a原创 2016-11-16 23:31:12 · 292 阅读 · 0 评论 -
Leetcode 330. Patching Array[hard]
题目: Given a sorted positive integer array nums and an integer n, add/patch elements to the array such that any number in range [1, n] inclusive can be formed by the sum of some elements in the array.原创 2016-11-16 17:42:45 · 267 阅读 · 0 评论 -
Leetcode 435. Non-overlapping Intervals[medium]
题目: Given a collection of intervals, find the minimum number of intervals you need to remove to make the rest of the intervals non-overlapping.Note: You may assume the interval’s end point is always原创 2016-11-16 16:47:33 · 310 阅读 · 0 评论 -
Leetcode 452. Minimum Number of Arrows to Burst Balloons[medium]
题目: here are a number of spherical balloons spread in two-dimensional space. For each balloon, provided input is the start and end coordinates of the horizontal diameter. Since it’s horizontal, y-coor原创 2016-11-16 15:47:56 · 394 阅读 · 0 评论 -
Leetcode 455. Assign Cookies[easy]
题目: Assume you are an awesome parent and want to give your children some cookies. But, you should give each child at most one cookie. Each child i has a greed factor gi, which is the minimum size of a原创 2016-11-16 15:00:56 · 660 阅读 · 0 评论 -
Leetcode 126. Word Ladder II[hard]
题目: Given two words (beginWord and endWord), and a dictionary’s word list, find all shortest transformation sequence(s) from beginWord to endWord, such that:Only one letter can be changed at a time E原创 2016-10-27 13:23:43 · 319 阅读 · 0 评论 -
Leetcode 153. Find Minimum in Rotated Sorted Array & Leetcode 154. Find Minimum in Rotated Sorted Ar
153题目: Suppose a sorted array 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).Find the minimum element.You may assume no duplicate exists in the arr原创 2016-10-26 20:32:48 · 278 阅读 · 0 评论 -
Leetcode 365. Water and Jug Problem[medium]
题目: You are given two jugs with capacities x and y litres. There is an infinite amount of water supply available. You need to determine whether it is possible to measure exactly z litres using these t原创 2016-10-26 19:01:05 · 298 阅读 · 0 评论 -
Leetcode 264. Ugly Number II[medium]
题目: Write a program to find the n-th ugly number.Ugly numbers are positive numbers whose prime factors only include 2, 3, 5. For example, 1, 2, 3, 4, 5, 6, 8, 9, 10, 12 is the sequence of the first 10原创 2016-11-27 21:54:21 · 335 阅读 · 0 评论