2014年11月13日

01背包问题

摘要: 01背包问题用DP(动态规划实现)背包容量int c = 10物品个数int n = 5物品重量w[] = {0, 2, 2, 6, 5, 4}物品价值v[] = {0, 6, 3, 5, 4, 6}结果存放result[][] = new int[n + 1][c + 1]//result[i][... 阅读全文

posted @ 2014-11-13 19:49 luckygxf 阅读(165) 评论(0) 推荐(0) 编辑

Valid Sudoku

摘要: Valid SudokuDetermine if a Sudoku is valid, according to:Sudoku Puzzles - The Rules.The Sudoku board could be partially filled, where empty cells are ... 阅读全文

posted @ 2014-11-13 16:50 luckygxf 阅读(192) 评论(0) 推荐(0) 编辑

Implement strStr

摘要: Implement strStr()Implement strStr().Returns the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack.这里用的BF算法... 阅读全文

posted @ 2014-11-13 15:55 luckygxf 阅读(151) 评论(0) 推荐(0) 编辑

动态规划(DP)

摘要: 动态规划,Dynamic programming,不是Dynamic planning ...将问题分成若干子问题,前面的解为后面的解所用,注意逆向推倒,找出递推公式,经典的01背包问题,晚点实现一下,这里搞一个LeetCode上面的题放着记录一下神马求二项式系数,斐波拉契...都可以用动态规划来实... 阅读全文

posted @ 2014-11-13 15:24 luckygxf 阅读(186) 评论(0) 推荐(0) 编辑

二分查找or折半查找

摘要: 1 package com.gxf.search; 2 3 /** 4 * 测试折半查找or二分查找 5 * @author xiangfei 6 * 7 */ 8 public class BiSearch { 9 10 /**11 * 非递归实现,从第1个元... 阅读全文

posted @ 2014-11-13 00:09 luckygxf 阅读(176) 评论(0) 推荐(0) 编辑

导航