For example there is a staricase N = 3 | ---|   |---|    | |---|            | ---|                  | There is N = 3 staricase, for each step, you can either take {1 or 2} step at a time. So asking how many ways you can get on N = 3 step: Answer: sho…
thanks prof. Abhiram Ranade for his vedio on Longest Common Subsequence 's back track search view in lecture 19, nice explanation indeed. // back track, recursive, 390 ms, O(m*n) memory #include <cstdio> #include <vector> #include <string&g…
For example we have 'a' -> 1 'b' -> 2 .. 'z' -> 26 By given "12", we can decode the string to give result "ab" or 'L', 2 ways to decode, your function should return 2 as an answer. Now asking by given "1246", what sh…
1. Longest Increasing Subsequence (LIS) problem unsorted array, calculate out the maximum length of subsequence with non-decreasing order. lis[i] = lis[j] + 1 if arr[i] > arr[j]; lis[i] is the lis with arr[i] as the last element. so to get the maximu…
For a given array, we try to find set of pair which sums up as the given target number. For example, we are given the array and target as: , , , ]; ; We should be able to find 2 pair, which sum up to 16: {,,} {,} We need to create a function to retur…
pid=4972" target="_blank" style="">题目链接:hdu 4972 A simple dynamic programming problem 题目大意:两支球队进行篮球比赛,每进一次球后更新比分牌,比分牌的计数方法是记录两队比分差的绝对值,每次进球的分可能是1,2,3分. 给定比赛中的计分情况.问说最后比分有多少种情况. 解题思路:分类讨论: 相邻计分为1-2或者2-1的时候,会相应有两种的的分情况 相邻计分之差大于3或…
http://acm.hdu.edu.cn/showproblem.php?pid=4972 ++和+1还是有区别的,不可大意. A simple dynamic programming problem Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 307    Accepted Submission(s): 117 Problem D…
动态规划(Dynamic Programming)是求解决策过程(decision process)最优化的数学方法.它的名字和动态没有关系,是Richard Bellman为了唬人而取的. 动态规划主要用于解决包含重叠子问题的最优化问题,其基本策略是将原问题分解为相似的子问题,通过求解并保存重复子问题的解,然后逐步合并成为原问题的解.动态规划的关键是用记忆法储存重复问题的答案,避免重复求解,以空间换取时间. 用动态规划解决的经典问题有:最短路径(shortest path),0-1背包问题(K…
Let's say we have two strings: str1 = 'ACDEB' str2 = 'AEBC' We need to find the longest common subsequence, which in this case should be 'AEB'. Using dynamic programming, we want to compare by char not by whole words. we need memo to keep tracking th…
We began our study of algorithmic techniques with greedy algorithms, which in some sense form the most natural approach to algorithm design. Faced with a new computational problem, we've seen that it's not hard to propose multiple possible greedy alg…