2014-03-20 02:55 题目:从(0, 0)走到(x, y),其中x.y都是非负整数.每次只能向x或y轴的正方向走一格,那么总共有多少种走法.如果有些地方被障碍挡住不能走呢? 解法1:如果没有障碍的话,组合数学,排列组合公式C(x + y, x). 代码: // 9.2 How many ways are there to go from (0, 0) to (x, y), if you only go left or up, and one unit at a time? #incl
区间动态规划问题一般都是考虑,对于每段区间,他们的最优值都是由几段更小区间的最优值得到,是分治思想的一种应用,将一个区间问题不断划分为更小的区间直至一个元素组成的区间,枚举他们的组合 ,求合并后的最优值.设F[i,j](1<=i<=j<=n)表示区间[i,j]内的数字相加的最小代价最小区间F[i,i]=0(一个数字无法合并,∴代价为0) 每次用变量k(i<=k<=j-1)将区间分为[i,k]和[k+1,j]两段 For p:=1 to n do // p是区间长度,作为阶段.
Given a set of candidate numbers (C) and a target number (T), find all unique combinations in C where the candidate numbers sums to T. The same repeated number may be chosen from C unlimited number of times. Note: All numbers (including target) will