This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 0-1 knapsack problem | |
For an overall introduction to knapsack problem, see https://en.wikipedia.org/wiki/Knapsack_problem | |
Function name: knapsack | |
Param: | |
items: an array of {w: v:} (where 'w' stands for weight, and 'v' stands for value) | |
capacity: a positive integer number | |
Will return max sum value that can reach, and the chosen subset to add up to the value. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Solve the knapsack problem using recursive descent. | |
// This wraps the actual solver below with a nice interface. | |
// It also handles non-integer cost, but then the complexity | |
// scales with the precision of the cost! | |
// | |
// obj is an object of named [cost, benefit] pairs, e.g. | |
// { banana: [5, 33], | |
// apple: [1, 12], | |
// kiwi: [1, 7] | |
// } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*<?php | |
//*/public class PhpJava { public static void main(String[] args) { System.out.printf("/*%s", | |
//\u000A\u002F\u002A | |
class PhpJava { | |
static function main() { | |
echo(//\u000A\u002A\u002F | |
"Hello World!"); | |
}} | |
//\u000A\u002F\u002A | |
PhpJava::main(); |