动态规划
动态规划的几个例子,帮助整理动态规划解决问题的思路
Vincent's Blog
A bug machine made in HUST
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
【动态规划】钢条切割问题
问题描述参见《算法导论》第十五章 动态规划,下面给出程序代码:#include<stdio.h>int max(int a,int b);int calc(int p[],int n);int p[11]={0,1,5,8,9,10,17,17,20,24,30};//p[i]存储长度为i的钢条价值int r[101]={0};//r[i]存储总长度为i,切割(或者不切割)所能达到的最大价值原创 2016-07-29 21:59:37 · 693 阅读 · 0 评论 -
【动态规划】爬楼梯问题
1.问题描述一个人爬楼梯,每次只能爬1个或两个台阶,假设有n个台阶,那么这个人有多少种不同的爬楼梯方法2.分析如果n==1,显然只有从0->1一种方法f(1)=1; 如果n==2,那么有0->1->2、0->2两种方法f(2)=2; 如果n==3,那么可以先爬到第1阶,然后爬两个台阶,或者先爬到第二阶,然后爬一个台阶,显然f(3)=f(2)+f(1); …… 推广到一般情况,对于n(n>=3原创 2016-07-28 10:25:22 · 13826 阅读 · 0 评论 -
【动态规划】【Leetcode】120. Triangle
1.题目描述Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjacent numbers on the row below.For example, given the following triangle[ [2], [3,4], ...原创 2019-02-02 17:11:36 · 430 阅读 · 0 评论 -
【动态规划】【leetcode】64. Minimum Path Sum
1. 题目描述Given a m x n grid filled with non-negative numbers, find a path from top left to bottom right which minimizes the sum of all numbers along its path.Note: You can only move either down or rig...原创 2019-02-01 19:14:51 · 351 阅读 · 0 评论 -
【动态规划】【Leetcode】63. Unique Paths II
1.题目描述A robot is located at the top-left corner of a m x n grid (marked ‘Start’ in the diagram below).The robot can only move either down or right at any point in time. The robot is trying to reach ...原创 2019-02-01 18:03:51 · 379 阅读 · 0 评论 -
【动态规划】凑硬币
算法 推荐阅读:从动态规划新手到专家 上面是在网上看到的一篇好文章,里面有一个凑硬币的问题 如果我们有面值为1元、3元和5元的硬币若干枚,如何用最少的硬币凑够11元? (表面上这道题可以用贪心算法,但贪心算法无法保证可以求出解,比如1元换成2元的时候) 首先我们思考一个问题,如何用最少的硬币凑够i元(i<11)?为什么要这么问呢? 两个原因:1.当我们遇到一个大问题时,总是习惯把问题的规模变小原创 2016-04-22 21:05:32 · 4703 阅读 · 3 评论 -
【动态规划】矩形覆盖
1. 题目描述假设我们可以用如图1所示21的小矩形横着或者竖着去覆盖更大的矩形,请问用8个21的小矩形去无重复的覆盖一个2*8的大矩形。总共有多少种方法。2.算法分析这道题出自《剑指offer》,也是一道考察动态规划的基础题。把覆盖28矩形的覆盖方法总数记为f(8).用第一个矩形去覆盖大矩形时,有两种选择,横放或者竖放。竖放时,右边有27的区域尚未被覆盖,那么剩下区域覆盖方法的总数为f(7...原创 2019-01-30 20:36:03 · 1524 阅读 · 0 评论
分享