算法入门
文章平均质量分 68
lovesnowbest
打卡专用博客
展开
-
背包问题复习2
背包问题复习21.对于数据量变大的01背包问题题目: 想法:首先这题的size和bag都很大,如果直接用动态规划套原来的模板肯定不行,但是我们发现对于value的值比较小。那么我们不妨反过来想这个问题,我们记录对于选到第n个物品,价值达到j的重量最小的情况。这样最后达到的目标肯定是装的最多的。 code:#include<iostream> #include <memory.h> #defi原创 2017-08-07 17:01:15 · 366 阅读 · 0 评论 -
背包问题复习
背包问题复习vijos 1025想法:记忆化搜索,或者动态规划都行,基础题。 code: #include<iostream> #include<memory.h> using namespace std; int n,size; int value[105],bag[105]; int record[105][1500]; int search(int count,int rest){原创 2017-08-06 17:00:57 · 1148 阅读 · 0 评论 -
哈希算法简介
introduction to HashTable1.What is hash?HashTable is a kind of map. The search process in hashtable holds o(1) complexity. You may think o(1), that’s impossible, since you need to traversal all the con原创 2017-08-03 14:15:27 · 286 阅读 · 0 评论 -
贪心算法poj 3617,3069,3253
挑战程序设计竞赛greedy problempoj 3617 Best Cow Line想法:先生成一个反着的字符串,(其实就是从两边开始找)先取出两边相比较小的字符串。当然这里有个问题,就是两边的头一个字符相同时,比较下一个字符,直到比较完整个字串为止,找到较小的那边的第一个字符加上。其实用strcmp就可以很好的解决上面描述的操作。 code: #include <iostream> #in原创 2017-08-05 15:15:13 · 321 阅读 · 0 评论 -
简单任务调度问题(贪心)
simple task scheduling problemToday we will talk about task scheduling problem using greedy thinking. In fact, greedy algorithm is quite uncommon, for most problems in our life can not be solved just b原创 2017-08-04 20:52:57 · 2758 阅读 · 0 评论 -
筛法快速求解素数
sieve methodreference:一般筛法求素数+快速线性筛法求素数1.naive method enum k from 2 to √n, if num % k ,then it’s not a prime 2.normal sieve First, let’s suppose all the nums are prime, from 2 to n. Second, for i=1:原创 2017-07-31 10:50:19 · 217 阅读 · 0 评论 -
约瑟夫问题(动态规划解法)
Josephus problem solution with o(n)1.Description People are standing in a circle waiting to be executed. Counting begins at a specified point in the circle and proceeds around the circle in a speci原创 2017-08-02 13:09:00 · 860 阅读 · 0 评论 -
使用二进制的思想降低时间复杂度
如何使用二进制解决问题正如通过高精度模拟可以获得500位以上的加减乘除运算外,当对于过大范围的运算我们可以将问题转化为二进制从而简便运算,使运算的一部分复杂度由n转化为log(n) - 首先是我们熟知的快速排序,即通过不断得将要排序的数组进行中等划分,进而递归成更小的数组,最后获得一个排序完的数组,qsort()其实就可以实现这个过程,不过手打的话可以更清楚一些。 code void quik原创 2017-02-25 08:58:35 · 969 阅读 · 0 评论 -
快速求解组合数(筛法+快速幂)
a quick way to calculate combinatorial number1.Why we need this method? Anyone who know how to print helloworld is also able to write a code to calculate a combinatorial number. However, the calculati原创 2017-08-01 13:52:10 · 693 阅读 · 0 评论 -
KMP算法小学生理解
KMP算法小学生理解1.简介看毛片算法可谓无人不知,相比于朴素字符串匹配,kmp算法将时间复杂度从o(N*M)缩减为o(N+M),实在为一大进步。其中N为模式串的长度,M为要从中寻找字符串的长度。概括的来说,我们首先对模式串进行一些列的打表,然后对M字串遍历就可以了。下面详细地讲一下这个kmp 2.kmp详解首先,朴素算法之所以可以被优化,其实是因为在匹配的过程中做了重复运算,举个例子来说把,如果原创 2017-10-04 15:30:56 · 392 阅读 · 0 评论