- 博客(8)
- 资源 (9)
- 收藏
- 关注
原创 回转顺序打印矩阵的改进算法
原题目见:http://blog.csdn.net/aegeaner/article/details/6744011如果使用二维数组,空间复杂度为O(N^2),事实上本题可以计算A[i][j]的通项公式,这样可以不用额外的矩阵存储空间,空间复杂度降为O(1)。思想是考虑从左上角开始的i*i子矩阵,只要在子矩阵扩张的外围补充(i*i+1)~(i+1)*(i+1)的序列即可。又可以看做是(i+
2012-04-26 18:20:58 1431
原创 C++仿函数
根据SGI官方文档,仿函数也叫函数对象(Function Object, or Functor),定义就是任何可以像函数一样被调用的对象。一个普通的函数是函数对象,一个函数指针当然也是,广义上说任何定义了operator()的类对象都可以看作是函数对象。最基本的函数对象概念包括Generator, Unary Function(一元函数), 和Binary Function(二元函数),分
2012-04-20 19:34:49 7373 1
原创 【动态规划】每对顶点之间的最短路径之Floyd-Warshall算法
《算法导论》25.2. 《计算机算法(C++版)》5.3.当然这个算法的实现是相当简单的,只使用了三重循环,时间复杂度为O(n^3)。但是重点是算法背后的思想,一般教材都把这个算法当做典型的图算法来讲,却没有讲到背后动态规划的思想。不过《计算机算法(C++版)》做到了这一点。此题的最优子结构很明显,假设i到j的最短路径是d,那么明显对路径上的任一点k,有d、d都是最短路径。但是这样的子问题很难
2012-04-13 17:02:21 2728 1
原创 一道腾讯笔试题的思路
受到w397090770博文的启发,写一下此题的思路(原文只有代码)。原博文地址:http://blog.csdn.net/w397090770/article/details/7449309已知数组a[n],求数组b[n].要求:b[i]=a[0]*a[1]*……*a[n-1]/a[i],不能用除法。 a.时间复杂度O(n),空间复杂度O(1)。 b.除了迭代器i,不允许使用任何其它
2012-04-13 14:01:48 1134
原创 【动态规划】多部图问题代码
《计算机算法(C++版)》5.2.用前向算法和后向算法进行动态规划,前向算法从后往前递推;后向算法,从前往后递推。C++代码如下:#include #include #include using namespace std;class Graph{private: const static int MAXSIZE = 101; int VertexNum; in
2012-04-12 21:32:36 1310
原创 【动态规划】最长递增子序列代码(UVA 10131)
题目:http://uva.onlinejudge.org/index.php?option=onlinejudge&Itemid=8&page=show_problem&problem=1072先按大象的体重排序,然后用DP求出大象IQ的最长递减子序列。为了输出这个子序列,每次子序列扩容时使用一个Pre[]数组保存前一个元素的索引,将索引压栈后正序输出。#include #incl
2012-04-11 22:05:16 1319
原创 【动态规划】矩阵链乘法代码
CLRS 15.2#include #include #include int m[101][101];int s[101][101];void matrix_chain_order(int p[], int n){ for(int i=1; i<=n; i++) m[i][i] = 0; for(int l=2; l<=n; l++)
2012-04-11 16:53:54 1133
原创 【动态规划】装配线调度代码
CLRS第二版15.1:#include int f[2][101];int l[2][101];int ff;int ll;void fastest_way(int n, int a[2][n], int t[2][n-1], int e[2], int x[2]){ f[0][0] = a[0][0] + e[0]; f[1][0] = a[1][0]
2012-04-11 13:45:21 980
The Architecture of Open Source Applications
2011-09-17
C++标准库,Boost简介
2007-05-20
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人