02 2013 档案
摘要:http://www.bianchengla.com/course/cpp/practise/problem?id=1310今天在北航oj上看到这道N皇后问题,记得做八皇后问题还是在大一c语言课上学的,当时还没接触算法,自然不懂回溯和递归,所以对八皇后的解法也只是理解了个大概,今天做到这题,上网搜了一下具体的做法,搜到一篇讲解很详细的blog:http://blog.csdn.net/hackbuteer1/article/details/6657109看明白后也就觉得不难写了,要做的就是算法的优化。自己写了非递归和递归的程序,位运算那个还是要好好理解一下吧。非递归:View Code #in
阅读全文
摘要:http://www.bianchengla.com/course/cpp/practise/problem?id=1269可以计算出投一次可得的分数是1*1/6 + 2 * 1/6 + 3 * 1/6 + 4 * 1/6 + 5 * 1/6 + 6 * 1/6 = 3.5 ;然后n次的期望就是3.5*n;代码:View Code #include <stdio.h>#include <stdlib.h>#include <string.h>#include <iostream>#include <algorithm>#include
阅读全文
摘要:其实这题和北航的oj上的一题一样,北航上的是汉语,题意就不说了,可以看一下北航上的翻译。http://www.bianchengla.com/course/cpp/practise/problem?id=1243直接递归会重复计算一些值,这样就会超时,最好的方法就是用记忆化搜索,用数组将值记录下来,当搜到已经计算过的值时直接使用就行了,避免再一次递归计算,这样会节省很多时间。代码:View Code #include <stdio.h>#include <stdlib.h>#include <string.h>#include <iostream>
阅读全文

浙公网安备 33010602011771号