Binary Representation and Dynamic Programming Solutions for Competitive Problems

Binary Number Decomposition Given an integer n, decompose it into distinct powers of two. If n is odd, output -1. #include <iostream> #include <vector> using namespace std; int main() { long long n; cin >> n; if (n % 2 != 0) { cout << -1 << endl; return 0; } vector< ...

Posted on Mon, 26 Oct 2026 16:11:28 +0000 by kevisazombie

The Multiple Knapsack Problem

The Multiple Knapsack Problem Given n types of items, where type i has c_i copies, value v_i, and weight w_i. We need to select items to maximize the total value in a knapsack with maximum capacity m. Solution 1 One approach is to transform the multiple knapsack problem into a 0-1 knapsack problem. The naive method would be to split each item t ...

Posted on Thu, 17 Sep 2026 16:40:37 +0000 by jeffz2008