quick-dp
Use dynamic programming quickly
Figure 1. Finding the shortest path in a graph using optimal substructure; a straight line indicates a single edge; a wavy line indicates a shortest path between the two vertices it connects (other nodes on these paths are not shown); the bold line is the overall shortest path from start to goal. Dynamic programming is both a mathematical optimization method and a computer programming method. The method was developed by Richard Bellman in the 1950s and has found applications in numerous fields, from aerospace engineering to economics. In both contexts it refers to simplifying a complicated problem by breaking it down into simpler sub-problems in a recursive manner. While some decision problems cannot be taken apart this way, decisions that span several points in time do often break apart recursively. Likewise, in computer science, a problem that can be solved optimally by breaking it into sub-problems and then recursively finding the optimal solutions to the sub-problems is said to have optimal substructure. --from wikipedia's Dynamic_programming
install
npm install quick-dp --save
example
const DynamicProgramming = ;// change coin question by dynamic programming { thismuch = much; }let coinTypeList = 125;let coinDP = coinTypeList13;let totalMoney = 0;let coinResult = coinDP;console/** * coinResult: * [ { coin: Coin { much: 5 }, num: 2 }, * { coin: Coin { much: 2 }, num: 1 }, * { coin: Coin { much: 1 }, num: 1 } ] */console //01 bag question by dynamic programming { thisweight = weight; } static let minWeight = 0; forlet i =0;i<ThingListlength;i++ ifi==0 minWeight = ThingListiweight; else if minWeight>ThingListiweightminWeight = ThingListiweight; return minWeight; { thisweight = weight; thisvalue = value; }let bag = 8;let ThingList = 23344556;let minWeight = Bag;let bagDP = ThingListbagweight;let unusedWeight = bagweight;let bagResult = bagDP;consoleconsole; // sort question by dynamic programminglet needSortList = 17682543;let sortDP = needSortListneedSortListlength-1;let countMap = {};let countIn;let sortSingleResultList = sortDP;countIn = 0;let sortResultASC = sortDPcountIn = 0;let sortResultDESC = sortDP console/** * sortResult: * [ 1, 2, 3, 4, 5, 6, 7, 8 ] */console/** * sortResult: * [ 8, 7, 6, 5, 4, 3, 2, 1 ] */console