上一页 1 ··· 6 7 8 9 10 11 12 13 下一页
摘要: 题目描述总结1. 和 Leetcode Palindrome cut 的设置方法类似2. 时间复杂度为 o(n^2), n 为任务个数3. 为了优化空间复杂度(同时也优化时间复杂度), dp[i] 表示第 i 个任务的开始时间到 endTime 之间能够获得的最大收益代码/* * source.cpp * * Created on: 2014-4-4 * Author: vincent */#include #include #include #include using namespace std;/* * dp[i] ~ time[i-endtime] 能够获得的最大收益 * ... 阅读全文
posted @ 2014-04-04 22:56 周卓 阅读(199) 评论(0) 推荐(0) 编辑
摘要: 题目描述总结:1. dp[i][0] 第 i 个位置上座男生方案数, dp[i][1] 第 i 个位置上座女生方案数2. dp[i][0] = dp[i-1][0] + dp[i-1][1], straight forward3. dp[i][0] = dp[i-2][0] + dp[i-3][0] +... dp[0][0] 枚举第一个男生出现的位置, 出现该男生之前的位子上座的都是女生代码/* * source.cpp * * Created on: 2014-4-4 * Author: vincent */#include #include #include using na... 阅读全文
posted @ 2014-04-04 21:12 周卓 阅读(340) 评论(0) 推荐(0) 编辑
摘要: 题目描述思路1. dp[i][j] 表示前 i 个操作中有 j 个入栈操作的方案数2. dp[i][j] = dp[i-1][j-1] + dp[i-1][j], 其中 j >= i/2.3. 为了方便起见, 非法的状态为 0, 比如 dp[3][1] = 0代码/* * source.cpp * * Created on: 2014-4-4 * Author: vincent *//* * dp[i][j] 前 i 个操作中有 j 个入栈操作的种类 * dp[i][j] = dp[i-1][j-1] + dp[i-1][j] * 其中, (i-j) #include #inclu... 阅读全文
posted @ 2014-04-04 20:47 周卓 阅读(297) 评论(0) 推荐(0) 编辑
摘要: 题目描述总结1. 用 BFS 实现 Dijkstra. 要点是, visited 后标记, 把某个点从优先队列取出后再标记代码 未通过九度测试 RE/* * source.cpp * * Created on: 2014-4-4 * Author: vincent */#include ... 阅读全文
posted @ 2014-04-04 20:12 周卓 阅读(204) 评论(0) 推荐(0) 编辑
摘要: 题目描述总结1. '_' 运算符不是 a*10 + b, 而是 a*(10 or 100) + b2. char * 与 string 的相互转化char* = string.c_str()string = char*3. 中缀表达式转后者表达式 参考:http://www.cnblogs.com/xinsheng/p/3591781.html4. 通用的中缀转后缀, 用 string 存数据比较好代码 未通过九度测试#include #include #include #include #include #include #include #include #include 阅读全文
posted @ 2014-04-03 11:19 周卓 阅读(285) 评论(0) 推荐(0) 编辑
摘要: 题目描述总结1. 将数字转化成 string 和字符串sprintf(char*, "%d", int)string = char*, 可以直接赋值2. std::sort 的比较函数写法bool cmp(const &int, const &int)3. 能用库函数, 尽量用库函数, 能减少错误代码未通过九度测试#include #include #include #include #include #include using namespace std;int n;int arr[1000];bool cmp(const int &a, con 阅读全文
posted @ 2014-04-03 09:26 周卓 阅读(172) 评论(0) 推荐(0) 编辑
摘要: 例题1:#include #include #include using namespace std; class A { char k[3]; public: virtual void aa() { } }; class B : public virtual A { char j[3]; public: virtual void bb() { } }; class C : public virtual B { char i[3]; public: virtual void cc() { } }; int main() { cout (pc); A* pa = dynamic_cas... 阅读全文
posted @ 2014-04-02 21:23 周卓 阅读(439) 评论(0) 推荐(0) 编辑
摘要: 单一的一般继承 可见以下几个方面:1. 虚函数表在最前面的位置2. 成员变量根据其继承和声明的顺序一次放在后面3. 在单一继承中, 被 overwrite 的虚函数在虚函数表中得到更新多重继承我们可以看到1. 每个父类都有自己的虚函数表2. 子类的成员函数被放在第一个父类的表中3. 内存布局中, 父类按照声明顺序一次排列4. 每个父类的虚表中的 f() 函数都被 overwrite 成了子类的 f(). 这样做就是为了解决不同父类类型的指针指向同一个子类实例.重复继承 我们可以看到, 最顶端的父类 B 其成员变量存在于 B1 和 B2 中, 并被 B 给继承下来了. 而在 D 中, 其有 B1 阅读全文
posted @ 2014-04-02 15:10 周卓 阅读(201) 评论(0) 推荐(0) 编辑
摘要: 虚函数表class Base { public: virtual voif f() { cout f(); //Derive::f() b2->f(); //Derive::f() b3->f(); //Derive::f() b1->g(); //Base1::g() b2->g(); //Base2::g() b3->g(); //Base3::g()转自:http://blog.csdn.net/haoel/article/details/1948051 阅读全文
posted @ 2014-04-02 14:46 周卓 阅读(187) 评论(0) 推荐(0) 编辑
摘要: 例题1: #include using namespace std;class A {protected: int m_data;public: A(int data = 0) { m_data = data; } int GetData() { return doGetData(); } virtual int doGetData() { return m_data; }};class B : public A {protected: int m_data;public: B(int data = 1) { m_data = data; } int doGetData() {... 阅读全文
posted @ 2014-04-02 11:42 周卓 阅读(197) 评论(0) 推荐(0) 编辑
上一页 1 ··· 6 7 8 9 10 11 12 13 下一页