【Edit Distance】cpp】的更多相关文章

题目: Given two words word1 and word2, find the minimum number of steps required to convert word1 to word2. (each operation is counted as 1 step.) You have the following 3 operations permitted on a word: a) Insert a characterb) Delete a characterc) Rep…
传送门:http://www.usaco.org/index.php?page=viewproblem2&cpid=126 好题啊好题,一开始就输给了这道题的想法! 先把原始状态以及目标状态换一种表示方式,比如输入数据是的初始状态是1 2 3 4,表示成1 2 2 3 3 3 4 4 4 4,目标状态是4 3 2 0,表示成1 1 1 1 2 2 2 3 3.那么这题就是求把原始状态转化为目标状态的最小代价,只有三种操作, add, remove, transport,所以这就是一个求Edit…
题意: 给出n个地雷所在位置,正好能够组成正方形的地雷就可以拿走..为了简化题目,只考虑平行于横轴的正方形.. 问最多可以拿走多少个正方形.. 思路: 先找出可以组成正方形的地雷组合cnt个.. 然后st = 1<<cnt.. 用位运算来考虑取哪一个组合可以拿走最多的地雷且满足题目条件.. Tips: 题目比较烦恼的地方是解决: ①. 所选集合里面的地雷会不会重复拿.. ②. 所选集合里面在同一个地方取走的地雷会不会比该地方题目给出的地雷数多.. 同一个地点可能有多个地雷,如果用去重就不好算多…
题意: 我们定义十进制数x的权值为f(x) = a(n)*2^(n-1)+a(n-1)*2(n-2)+...a(2)*2+a(1)*1,a(i)表示十进制数x中第i位的数字. 题目给出a,b,求出0~b有多少个不大于f(a)的数. 思路: 数位DP,用来学习数位DP了. <数位DP> 所谓数位DP就是基于考虑数字的每一位来转移的DP. 例如求比456小的数,可以这么考虑, 4          5               6   4       5             (0~6) 4…
题目: Determine if a Sudoku is valid, according to: Sudoku Puzzles - The Rules. The Sudoku board could be partially filled, where empty cells are filled with the character '.'. A partially filled sudoku which is valid. Note:A valid Sudoku board (partia…
题目: Given an array and a value, remove all instances of that value in place and return the new length. The order of elements can be changed. It doesn't matter what you leave beyond the new length. 代码: class Solution { public: int removeElement(int A[…
题目: Given a collection of numbers that might contain duplicates, return all possible unique permutations. For example,[1,1,2] have the following unique permutations:[1,1,2], [1,2,1], and [2,1,1]. 代码: class Solution { public: vector<vector<int>>…
题目: Given a collection of integers that might contain duplicates, nums, return all possible subsets. Note: Elements in a subset must be in non-descending order. The solution set must not contain duplicate subsets. For example,If nums = [1,2,2], a sol…
题目: Given an array with n objects colored red, white or blue, sort them so that objects of the same color are adjacent, with the colors in the order red, white and blue. Here, we will use the integers 0, 1, and 2 to represent the color red, white, an…
题目: Sort a linked list in O(n log n) time using constant space complexity. 代码: /** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */ class Solution { public: ListNo…