摘要: 最大自序和问题。给出一个长度为n的序列求最大连续和。换句话说,要求找到1 best) { best = sum; // 更新最大值 } } }显然有优化:设直观含义是连续子序列之和等于两个前缀和之差。用这个结论,省略最内层的循环。demo2 S[0] = 0; for (int i = ... 阅读全文
posted @ 2015-06-20 23:51 Say舞步 阅读(227) 评论(0) 推荐(0) 编辑
摘要: #include using namespace std;void printPermutation(int n, int* A, int cur){ if (cur == n) { // 递归边界 for (int i = 0; i #include #include using namespa... 阅读全文
posted @ 2015-06-20 22:17 Say舞步 阅读(337) 评论(0) 推荐(0) 编辑
摘要: 根据状态进行bfs,手动打表维护骰子滚动。AC代码:#include #include #include #include #include #include #include #include #include #include #include #include #include #includ... 阅读全文
posted @ 2015-06-20 17:06 Say舞步 阅读(208) 评论(0) 推荐(0) 编辑
摘要: 先搞清楚这个数不一定是二叉树,然后把树分段,把所有子树用队列存放。搞清楚BFS和DFS的关系就很明确了。AC代码:#include #include #include #include #include #include #include #include #include #include #in... 阅读全文
posted @ 2015-06-20 15:56 Say舞步 阅读(269) 评论(0) 推荐(0) 编辑
摘要: A simple solitaire card game called 10-20-30 uses a standard deck of 52 playing cards in which suit is irrelevant. The value of a face card (king, que... 阅读全文
posted @ 2015-06-20 14:27 Say舞步 阅读(252) 评论(0) 推荐(0) 编辑
摘要: 模拟题,调制了一晚上,略伤心,算法速度比较慢。。。用了1秒多,比较直观的做法。AC代码:#include #include #include #include #include #include #include #include #include #include #include #includ... 阅读全文
posted @ 2015-06-20 01:32 Say舞步 阅读(156) 评论(0) 推荐(0) 编辑
摘要: Input: petri.in A Petri net is a computational model used to illustrate concurrent activity. Each Petri net contains some number of places (represente... 阅读全文
posted @ 2015-06-19 17:14 Say舞步 阅读(372) 评论(0) 推荐(0) 编辑
摘要: 刚开始想用结论:若最终天平平衡,则在同一个深度的所有结点,无论它的祖先结点是什么,重量都应该相同。并且上一层的重量应该是下一层的2倍。证明其实是显然的。。之后只需要把所有的结点分块,然后取结点最多的块,其余的结点都要修改,就是答案。但是代码并不是很简洁,后来参考别人的做法,知道可以反过来想:要使得改... 阅读全文
posted @ 2015-06-19 15:43 Say舞步 阅读(230) 评论(0) 推荐(0) 编辑
摘要: dfs和bfs都能做,我用dfs遍历了,dfs应该要快,我AC了之后找了找网上bfs写的,时间是我的9倍以上,都比较慢,所以用dfs还是很不错的,注意递归的条件。AC代码:#include #include #include #include #include #include #include #... 阅读全文
posted @ 2015-06-19 13:54 Say舞步 阅读(165) 评论(0) 推荐(0) 编辑
摘要: 、bfs求最短路,经典数据结构题目。AC代码:#include #include #include #include #include #include #include #include #include #include #include #include #include #include ... 阅读全文
posted @ 2015-06-19 09:26 Say舞步 阅读(131) 评论(0) 推荐(0) 编辑