
算法设计
zjumath
这个作者很懒,什么都没留下…
展开
-
递归求解8皇后问题
经典的回溯算法X[i] 表示第i行放置的皇后的所在列,这样一个数组就可以表示一个解 place 函数检查合法性,Nqueens2 函数我自己写的递归函数 #include #include /*检查可不可以放置一个新的皇后*/bool place(int k, int *X){ int i = 0; while(i { if((X[i]==X[k])||(abs(X[i]原创 2009-06-06 14:15:00 · 695 阅读 · 0 评论 -
快速排序
#include using namespace std;void QuickSort(int array[], int low, int high);int Partition(int array[], int i, int j);void PrintArray(int array[], int n);int main(int argc, char* argv[]){ int numAr原创 2009-06-07 22:23:00 · 509 阅读 · 0 评论 -
[zz] n个元素的第2小元素
n个元素的第2小元素 Show how to find the second smallest elementofn elements using n+log(n) -2 comparisons. To find the smallest element construct atournamentas follows: Compare all the numbers in pair转载 2009-07-01 16:27:00 · 729 阅读 · 0 评论 -
kmp字符串匹配算法
[ code=C C++ ][#include #include #include void KmpMatcher(char *sourceText, char *str);void ComputePrefix(int *pi, char *str);int main(int argc, char *argv[]){ char sourceText[] = "DocumentsandSet原创 2009-09-09 10:19:00 · 537 阅读 · 0 评论