We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
- Prepare
- Algorithms
- Dynamic Programming
- Knapsack
- Discussions
Knapsack
Knapsack
Sort by
recency
|
262 Discussions
|
Please Login in order to post a comment
Annoyingly ... we hade to update the main function to get the code to loop through all test cases ... shoulda put that in the instructions.
Python: you need to FIX THE MAIN!
It should be:
Resolution:
solution using C with recursion function. What I did here is to try to get every possible combination in an optimal way because there is no other way to know the highest possible sum because there are no limits on the numbers used to get this sum. So for each element in the array, start from the first index and get the maximum sum using it. Store this sum, and each time, reduce this sum by the value in the specific index. and pass this sum to the next index. and do it recursively for all indexes.
for main function issues, just do a for loop t times from
char** first_multiple_input = split_string(rtrim(readline()));
untilfprintf(fptr, "%d\n", result);
the code :
I dont like such questions and platforms where I need to update my main() function as well to pass multiple test cases. Here I was waiting and searching error in my solution that why only one test case result is getting print, only to figure out I had to myslef run loop for all t values.
Fraction Knapsack
include
include
include
include
include
using namespace std;
bool com (const vector& a,const vector& b) { return a[2]>b[2]; } int main() { int n =0; cin>>n;
cin>>w;
}