摘要:
回溯法,在以前也是会的,只不过没有系统的学习,只是从题目中接触了一些。今天,系统的学习了一下,颇有感触。对于回溯,书上的模版是这样的:bool finished = FLASE; /*found all solutions yet? */backtrack(int a[], int k, data input){ int c[MAXCANDIDATES]; // candidates for next position int ncandidates; //next position candidate count int i; //counter if(i... 阅读全文
posted @ 2013-04-05 16:54
Still_Raining
阅读(245)
评论(0)
推荐(0)
摘要:
在网上看到一篇相关的文章,感叹算法的巧妙。用O(n)复杂度搞定。异或操作(^)——(对于位操作)相同为0,相异为1.比如:1^0 = 1, 1 ^1=0这样:两个相同的数异或就为0任何数和0异或为自己(转化到位。1^0 =1,0^0=0对于2,1,3,2,1, (2^2)^(1^1)^3=3.如此就能将不成对的3找出来。异或具有交换律,所以可以按顺序计算,2^1^3^2^1=3。代码如下:#include <stdio.h>#include <string.h>#include <stdlib.h>int a[7] = {1, 2, 1, 2, 3, 5, 阅读全文
posted @ 2013-04-05 13:25
Still_Raining
阅读(241)
评论(0)
推荐(0)
浙公网安备 33010602011771号