贪心类题目目前除了正则匹配(Wildcard Matching)(据说其实是DP)那道还没做其他的免费题目都做了,简单做个总结。贪心的奥义就是每一步都选择当前回合”可见范围“(即可得知的信息)内的最优,而在每一步都仅选择当前回合”可见范围“内的最优这一策略下能够导致全局最优的结果的情况使用贪心就会是...
分类:
其他好文 时间:
2015-09-20 00:25:14
阅读次数:
305
Typical solution: convert it to Maximum Array problem.And here is my solution: O(n) by using Greedy strategy on this equation: sum[i..j] = sum[0..j] -...
分类:
其他好文 时间:
2015-09-13 14:33:22
阅读次数:
166
One-pass Greedy solution. So beautiful.class Solution {public: void wiggleSort(vector& nums) { for(int i = 1; i nums[i]) ...
分类:
其他好文 时间:
2015-09-11 06:38:20
阅读次数:
158
上次我在http://www.cnblogs.com/Philip-Tell-Truth/p/4787067.html这里,稍微讲了一下一种很普通的贪婪的算法,其实这个算法一开始是用来做压缩程序的,就是最著名的Huffman压缩算法 那么这个算法是怎么样的呢,我们知道,我们的...
分类:
其他好文 时间:
2015-09-06 22:49:38
阅读次数:
378
Fence Repair 问题大意:农夫约翰为了修理栅栏,要将一块很长的木块切割成N块,准备切成的木板的长度为L1,L2...LN,未切割前的木板的长度恰好为切割后木板的长度的总和,每次切断木板的时候,需要的开销为这块木板的长度,例如长...
分类:
其他好文 时间:
2015-09-06 21:32:18
阅读次数:
230
2015-09-06 北大神奇的萨鲁曼军队 问题大意:萨鲁曼白想要让他的军队从sengard到Helm’s Deep,为了跟踪他的军队,他在军队中放置了魔法石(军队是一条线),魔法石可以看到前后距离为R的距离,为了让...
分类:
其他好文 时间:
2015-09-06 20:14:33
阅读次数:
206
Greedy Gift GiversA group of NP (2 ≤ NP ≤ 10) uniquely named friends has decided to exchange gifts of money. Each of these friends might or might not ...
分类:
其他好文 时间:
2015-08-28 19:10:32
阅读次数:
154
/*ID: modengd1PROG: gift1LANG: C++*/#include #include#includeusing namespace std;char names[30][20];int acount[30];int counter,N;int getIndex(char nam...
分类:
其他好文 时间:
2015-08-26 01:34:57
阅读次数:
184
print "Performing greedy feature selection..."
score_hist = []
N = 10
good_features = set([])
# Greedy feature selection loop
while len(score_hist) score_hist[-2][0]:
scores = []
for f in ran...
分类:
编程语言 时间:
2015-08-11 21:31:26
阅读次数:
269
August 10, 2015有二种解法, Greedy算法, 和DP算法. 二种算法都通过leetcode online judge. 贪婪算法, 花了一个小时理解代码, 修改后很好理解.Problem statement:Find the contiguous subarray within a...
分类:
其他好文 时间:
2015-08-11 09:44:20
阅读次数:
127