摘要: 力扣115:不同的子序列 https://leetcode-cn.com/problems/distinct-subsequences/ 题解: AC代码 class Solution { public: int numDistinct(string s, string t) { int sl = 阅读全文
posted @ 2020-12-27 15:18 VanHope 阅读(82) 评论(0) 推荐(0) 编辑
摘要: 部分背包问题、Huffman编码、活动选择 提出贪心策略:观察问题特征,构造贪心选择 证明策略正确:假设最优方案,通过替换证明 1 部分背包 按性价比大小从小到大排序,先选择性价比高的物品; def F_Knapsack(n,p,v,C) { 把所有物品按照价值/体积的比升序; //排序时间复杂度n 阅读全文
posted @ 2020-12-27 15:10 VanHope 阅读(78) 评论(0) 推荐(0) 编辑
摘要: 图算法 1 BFS def BFS(G<V,E>, s) { 新建:队列Q 前驱数组 pred[] 距离数组 dist[] 颜色数组 celor[] // 初始化 for(u in V) { color[u] = white; pred[u] = NULL; dist[u] = INF; } col 阅读全文
posted @ 2020-12-27 14:28 VanHope 阅读(79) 评论(0) 推荐(0) 编辑