摘要: 分治与贪心 分治 贪心策略 step1 分:问题分解 问题分解为多个子问题 step2 治:逐个击破 子问题求局部最优解 step3 合:合并求解 局部最优解进行组合 对于分治,问题分解之后可能还需要继续分解。对于贪心策略,子问题将无需继续分解。 实列 快速排序算法就用到了分治策略 求解Fibona 阅读全文
posted @ 2022-02-08 19:50 dctwan 阅读(75) 评论(0) 推荐(0) 编辑
摘要: 求xn 朴素方法 遍历从1到n的所有数然后累乘即可 int simplePower(int x, int n){ int answer = 1; for(int i = 1; i <= n; ++i){ answer *= i; } return answer; } 时间复杂度为O(n) 快速幂 原 阅读全文
posted @ 2022-02-08 19:37 dctwan 阅读(28) 评论(0) 推荐(0) 编辑
摘要: 题目描述 Assume the coasting is an infinite straight line. Land is in one side of coasting, sea in the other. Each small island is a point locating in the 阅读全文
posted @ 2022-02-08 15:20 dctwan 阅读(27) 评论(0) 推荐(0) 编辑
摘要: poj3104:Drying——贪心(二分+判定) http://poj.org/problem?id=3104 Jane wants to perform drying in the minimal possible time. She asked you to write a program t 阅读全文
posted @ 2022-02-08 09:03 dctwan 阅读(68) 评论(0) 推荐(0) 编辑
摘要: poj2456:Aggressive cows——贪心(二分+判定) http://poj.org/problem?id=2456 Farmer John has built a new long barn, with N (2 ⇐ N ⇐ 100,000) stalls. The stalls a 阅读全文
posted @ 2022-02-08 08:01 dctwan 阅读(51) 评论(0) 推荐(0) 编辑