摘要:
ou are climbing a stair case. It takes n steps to reach to the top.Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top?分析:类似斐波那契序列,使用动态规划的思想。定义f(n)为台阶数为n时青蛙跳到台阶顶部的方法数。那么当n>2 时f(n) = f(n-1) + f(n-2) f(1) = 1; f(2) = 2;class Solution {public: int climbSta 阅读全文
摘要:
写本篇主要是为了将基础知识梳理一遍,天天加一些基本东西,以后复习时可以返回来看看。数据结构&&基础算法:基本算法: 二分查找二叉树: 二叉树的各种遍历位操作:排序:排序算法总结图论: 总结RMQ : ST 阅读全文
摘要:
1 prim 算法 O(n2) 贪心/* 最小生成树Prim 算法: 贪心思想,随机选择一个点当做最小生成树的初始节点,然后把图的顶点分成A集合(含初始节点), B集合(剩余节点)每次选择A集合中的点到B集合中点的最短距离的边,然后用加入的点去松弛A集合点到B集合点的距离信息。不断迭代, 最终得到最小生成树。*/struct Edge{ int start_, end_; float weight_;};void prim(vector> &map, Edge *&mist){ int n = map.size(); if(n > &grap... 阅读全文