简体   繁体   中英

Given an array of objects of varying durations, how can you find all possible arrangements within a given time frame

So if you have a set objects that each have different duration values, like songs for example - and you want to create a bunch of playlists that all fit within a specific timeframe, what would be the easiest way of going about this?

Example:

  • Song 1 : 1:30
  • Song 2 : 2:56
  • Song 3 : 3:56
  • Song 4 : 4:54
  • Song 5 : 1:00

Maximum duration: 5:00

Possible Combinations: (Song 1, Song 2), (Song 2, Song 1), (Song 2, Song 5), (Song 5, Song 2), (Song 3, Song 5), (Song 5, Song 3), (Song 4).

I am curious about neural networks, but do not know much about them or if they would be easily applied to this problem. The target language is php.

It would be ideal if an allowed variance could be provided like +/- 0:30 so that generated playlists could fall either below or above the maximum limit by the given amount.

Any help would be appreciated, just trying to figure out how to begin approaching this problem, Thanks!

This is a bin-packing problem. You can sort the list and then you can try to fill the time frames with the best fit,the next fit, the first fit or worst fit. Imagine you have more then one time frame and you need to find the smallest amount of time frames with a given playlist.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM