删除链表结点注意保证链表不会断开。删除的节点是尾结点时,并不能保证是O(1)时间。但平均下来时间复杂度仍然保持在O(1)。...
分类:
其他好文 时间:
2014-05-26 03:38:22
阅读次数:
166
下面是反转一个链表的两种方法:
一、循环算法
// //反转一个链表,循环算法
// LinkList Reverse(LinkList& head)
// {
// // if(!head)
// // return head;
// //此时不用判断head是否为空,如是空的话返回的也是空
// LinkList cur = head;
// LinkList hou;
//...
分类:
其他好文 时间:
2014-05-26 03:20:47
阅读次数:
211
思路:1、反转后头结点变化;2、注意链表可能断裂的情形...
分类:
其他好文 时间:
2014-05-26 03:13:18
阅读次数:
163
http://poj.org/problem?id=2449
大致题意:给出一个有向图,求从起点到终点的第K短路。
K短路A*算法讲解:
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define LL long...
分类:
其他好文 时间:
2014-05-24 23:39:47
阅读次数:
352
【题目】
Given a matrix of m x n elements (m rows, n columns), return all elements of the matrix in spiral order.
For example,
Given the following matrix:
[
[ 1, 2, 3 ],
[ 4, 5, 6 ],
[ 7, 8, 9 ]
]
You should return [1,2,3,6,9,8,7,4,5].
【题意】
螺旋输出MxN...
分类:
其他好文 时间:
2014-05-24 23:11:02
阅读次数:
279
【题目】
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,1,?5,4],
the contiguous subarray [4,?1,2,1] has the largest sum = 6.
【题意】
给定一个数组,找出和最大的子数组,返回...
分类:
其他好文 时间:
2014-05-24 22:19:17
阅读次数:
260
【题目】
Given 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.
Determine if you are able to reach the last index.
For example:...
分类:
其他好文 时间:
2014-05-24 20:44:39
阅读次数:
221
问题:
有N件物品和一个容量为V的背包。第i件物品的费用是c[i],价值是w[i]。这些物品被划分为若干组,每组中的物品互相冲突,最多选一件。求解将哪些物品装入背包可使这些物品的费用总和不超过背包容量,且价值总和最大。
算法:
这个问题变成了每组物品有若干种策略:是选择本组的某一件,还是一件都不选。也就是说设f[k][v]表示前k组物品花费费用v能取得的最大权...
分类:
其他好文 时间:
2014-05-24 20:39:29
阅读次数:
190
1.算法简介
协同过滤(collaborative filtering)的核心思想:利用其他用户的行为来预测当前用户。协同过滤算法是推荐系统中最基本的,同时在业界广为使用。根据使用的方法不同,可以分为基于用户(user-based)、基于物品(item-based)的最近邻推荐。
基于用户的最近邻推荐的主要思想:对于一个给定的评分集,找出与当前用户u口味相近的k个用户;然后,对...
分类:
其他好文 时间:
2014-05-24 17:59:03
阅读次数:
308