åçèšç»æ³Intermediate
0/1ããããµãã¯åé¡
äžããããéããšäŸ¡å€ãæã€ã¢ã€ãã ãéžæããééå¶éå ã§ç·äŸ¡å€ãæå€§åããå€å žçãªåçèšç»æ³ã®åé¡ã§ããåã¢ã€ãã ã¯äžåºŠã ãåãããšãã§ããŸãïŒ0/1ïŒããªãœãŒã¹é åãããŒããã©ãªãªæé©åã貚ç©ç©èŒã«å¿çšãããŸãã
#dynamic-programming#optimization#combinatorial#np-complete
Complexity Analysis
Time (Average)
O(n à W)Expected case performance
Space
O(n à W)Memory requirements
Time (Best)
O(n à W)Best case performance
Time (Worst)
O(n à W)Worst case performance
ð CLRS Reference
Introduction to Algorithmsâ¢Chapter 16â¢Section 16.2
How it works
- ⢠0/1 Knapsack: maximize value within capacity limit
- ⢠Dynamic programming approach
- ⢠O(n à W) time, O(n à W) space complexity
- ⢠Each item can be taken once or not at all
- ⢠Formula: dp[i][w] = max(dp[i-1][w], dp[i-1][w-wt[i]] + val[i])
Step: 1 / 0
500ms
SlowFast
Keyboard Shortcuts
Space Play/Pauseâ â StepR Reset1-4 Speed
Real-time Statistics
Algorithm Performance Metrics
Progress0%
Comparisons
0
Swaps
0
Array Accesses
0
Steps
1/ 0
Algorithm Visualization
Step 1 of 0
Initialize array to begin
Default
Comparing
Swapped
Sorted
Code Execution
Currently executing
Previously executed
Implementation