我有一个背包问题的简单解决方案的代码,我想获取所选项目的索引列表,目前它正在返回所选项目的值的总和。任何帮助将不胜感激。Java代码:
/* package whatever; // don't place package name! */
import java.util.*;
import java.lang.*;
import java.io.*;
/* Name of the class has to be "Main" only if the class is public. */
/* A Naive recursive implementation of 0-1 Knapsack problem */
class Knapsack
{
// A utility function that returns maximum of two integers
static int max(int a, int b) {
return (a > b)? a : b; }
// Returns the maximum value that can be put in …Run Code Online (Sandbox Code Playgroud)