随笔分类 - 算法
关于算法的学习和心得
摘要:int LCS(string str1, string str2) //返回最长公共字串长度{ //创建矩阵 int** martix; martix = new int*[str1.length()+1]; for(int i =0; imax) {...
阅读全文
摘要:原题:《数据结构与算法分析C++描述(第三版)》练习2.27问题描述:N*N矩阵,每一行从左到右增加,每一列从上到下增加。给出O(N)最坏情形算法决定是否数X在该矩阵中。代码: 1 #include 2 #include 3 #include 4 #include 5 6 using namespace std; 7 8 int searchx(vector > v,int x) 9 {10 int i(0),j(0);11 i=v.size()-1;12 while(j=0)13 {14 while(v[i][j] tv;32 ve...
阅读全文
摘要:原题:《数据结构与算法分析C++描述(第三版)》练习2.26问题描述:大小为N的数组的主元素是出现次数超过N/2的元素。找到给定数组的主元素,若没有,应指出。完整代码: 1 #include 2 #include 3 4 using namespace std; 5 6 void cand(vector &v) 7 { 8 vector::iterator itf = v.begin(); 9 vector::iterator ite = v.begin();10 while(itf!=v.end()&&ite!=v.end())11 {12 ...
阅读全文

浙公网安备 33010602011771号