Subset-sum problem in PHP with MySQL

血红的双手。 提交于 2019-12-04 16:03:56

What you are describing is a Knapsack Problem. When I was in college, we used Dynamic Programming to attack problems like this.

The brute-force methods (just try every combination until one (or more) works is a complexity O(n!), or factorial-length problem - extremely lengthy to iterate through and calculate!

If your times for tracks are stored as an int (in seconds seems the easiest math to me), then your knapsack size is 3300-3900 (3600 seconds == 1 hour).

Is your goal to always return the first set that matches, or to always return a random set?

Note - by bounding your sack size, you greatly expand the number of possible answers.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!