摘要: 网易实习生 题解:超大容量背包问题。因为背包容量过大,不能用背包解法。而物品个数最多只有三十个,但是所有状态也高达2^30,所以将所有物品折半dfs 代码: #include<iostream> #include<vector> #include<cstdio> #include<cstring> 阅读全文
posted @ 2018-03-29 11:53 Silence、 阅读(158) 评论(0) 推荐(0) 编辑
摘要: 5. Longest Palindromic Substring 最长回文子串 题意:找到字符串的最长回文子串(子串是连续的,子序列是可以间断的) 我的解法:将每两个字符中间插入一个‘#’,这个就可以一起判断奇数回文串和偶数回文串,分别将每个字符作为中心往两侧最长回文,更新结果。时间复杂度O(n^2 阅读全文
posted @ 2018-03-23 14:45 Silence、 阅读(126) 评论(0) 推荐(0) 编辑
摘要: 1、priority_queue自定义比较结构 class Solution { public: struct cmp { bool operator()(int &a, int &b) const { //因为优先出列判定为!cmp,所以反向定义实现最小值优先 return a>b; } }; v 阅读全文
posted @ 2018-03-15 10:03 Silence、 阅读(148) 评论(0) 推荐(0) 编辑
摘要: 587. Erect the Fence 题意:输出把所有点包围起来的轮廓线上的点 我的思路:凸包问题,Graham-Scan算法 我的代码: class Solution { public: static bool cmp(Point& a, Point& b) { if (a.y == b.y) 阅读全文
posted @ 2018-01-25 17:05 Silence、 阅读(483) 评论(0) 推荐(0) 编辑
摘要: 计第一 内篇 权谋组:《计》、《作战》、《谋攻》 形势组:《形》、《势》、《虚实》 外篇 军争组:《军争》、《九变》、《行军》、《地形》、《九地》 其他:《火攻》、《用间》 权谋 “ 以正治国,以奇用兵”——老子 战争是政治的继续,“奇”以“正”为前提,“正不获意”,才用“权”。 “先计而后战” “ 阅读全文
posted @ 2017-07-01 12:54 Silence、 阅读(484) 评论(0) 推荐(0) 编辑
摘要: 208. Implement Trie (Prefix Tree) 题意:构造Trie树的插入、查找操作 我的思路:字典树模板 我的代码: class Trie { public: vector<vector<int> > ch; vector<int> val; /** Initialize yo 阅读全文
posted @ 2017-06-06 20:38 Silence、 阅读(312) 评论(0) 推荐(0) 编辑
摘要: 207. Course Schedule 题意:每个课程会有一个先修课程,给定一张图,判断能否按顺序修完所有课程 我的思路:拓扑排序裸题 我的代码: class Solution { public: struct Node { int to, next; }; bool canFinish(int 阅读全文
posted @ 2017-05-30 21:31 Silence、 阅读(496) 评论(0) 推荐(0) 编辑
摘要: 118. Pascal's Triangle 题意:输出杨辉三角前n行 我的思路:大水题 我的代码: class Solution { public: vector<vector<int>> generate(int numRows) { vector<vector<int>> ans; if (n 阅读全文
posted @ 2017-05-01 22:05 Silence、 阅读(347) 评论(0) 推荐(0) 编辑
摘要: 92. Reverse Linked List II 题意:将链表中第m到第n个元素翻转 我的思路:指针数组 我的代码: class Solution { public: ListNode* reverseBetween(ListNode* head, int m, int n) { vector< 阅读全文
posted @ 2017-03-30 16:13 Silence、 阅读(202) 评论(0) 推荐(0) 编辑
摘要: 5. Longest Palindromic Substring 题意:返回字符串的最长回文子串 我的思路:dp,http://blog.csdn.net/kangroger/article/details/37742639 我的代码: class Solution { public: string 阅读全文
posted @ 2017-03-25 22:45 Silence、 阅读(229) 评论(0) 推荐(0) 编辑