随笔分类 -  算法导论

摘要:本篇文章作为个人的背包问题学习资料,来自转载 "dd大牛的《背包九讲》" . P01: 01背包问题 题目 有N件物品和一个容量为V的背包。第i件物品的费用是c[i],价值是w[i]。求解将哪些物品装入背包可使这些物品的费用总和不超过背包容量,且价值总和最大。 基本思路 这是最基础的背包问题,特点是 阅读全文
posted @ 2018-01-28 21:23 A-Little-Nut 阅读(318) 评论(0) 推荐(0)
摘要:Given a non negative integer number num. For every numbers i in the range 0 ≤ i ≤ num calculate the number of 1's in their binary representation and r 阅读全文
posted @ 2018-01-21 10:07 A-Little-Nut 阅读(172) 评论(0) 推荐(0)
摘要:You are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed, the only constraint stopping yo 阅读全文
posted @ 2018-01-21 09:04 A-Little-Nut 阅读(154) 评论(0) 推荐(0)
摘要:Given an integer array nums, find the sum of the elements between indices i and j (i ≤ j), inclusive. Example: Note: 1: You may assume that the array 阅读全文
posted @ 2018-01-20 21:37 A-Little-Nut 阅读(143) 评论(0) 推荐(0)
摘要:Find the contiguous subarray within an array (containing at least one number) which has the largest sum. For example, given the array [ 2,1, 3,4, 1,2, 阅读全文
posted @ 2018-01-20 20:36 A-Little-Nut 阅读(177) 评论(0) 推荐(0)
摘要:Eva is trying to make her own color stripe out of a given one. She would like to keep only her favorite colors in her favorite order by cutting off th 阅读全文
posted @ 2018-01-20 19:53 A-Little-Nut 阅读(481) 评论(0) 推荐(0)
摘要:在分治策略中递归地求解一个问题,在每层递归中应用如下三个步骤: 分解 : 将问题划分成一些子问题,子问题的形式与原问题一样,只是规模更小。 解决 : 递归地求解子问题。如果子问题的规模足够小,则停止递归,直接求解。 合并 : 将子问题的解组合成原问题的解。 最大子数组问题 分治策略求解(nlg(n) 阅读全文
posted @ 2018-01-18 18:21 A-Little-Nut 阅读(1209) 评论(0) 推荐(0)
摘要:算法的时间复杂度和空间复杂度-总结 通常,对于一个给定的算法,我们要做 两项分析。第一是从数学上证明算法的正确性,这一步主要用到形式化证明的方法及相关推理模式,如循环不变式、数学归纳法等。而在证明算法是正确的基础上,第二部就是分析算法的时间复杂度。算法的时间复杂度反映了程序执行时间随输入规模增长而增 阅读全文
posted @ 2018-01-18 15:02 A-Little-Nut 阅读(464) 评论(0) 推荐(0)
摘要:1 #include 2 using namespace std; 3 void Insertion_sort(long int a[],int s,int n){ 4 int temp,i,j; 5 for(i=s+1;i=s;j--){ 8 if(a[j]>temp) a[j+1]=a[j]; 9 else bre... 阅读全文
posted @ 2018-01-16 09:46 A-Little-Nut 阅读(420) 评论(0) 推荐(0)