State Compression Dynamic Programming: Cannon Positioning and Non-attacking Kings Problems
In an N×M (N<100, M<10) grid, we need to place cannons on plains (P) while avoiding mountains (H). Cannons attack in a cross pattern: 2 cells left and right horizontally, and 2 cells up and down vertically. Cannons cannot attack each other. The goal is to maximize the number of cannons placed.
Example input:
5 4
PHPP
PPHH
PPPP
PHPP
PHHP
...
Posted on Fri, 17 Jul 2026 16:18:25 +0000 by andymike07
Identifying a Valid Row Subset in a Binary Matrix via Bitmasking
In a binary matrix of size m x n, a subset of rows is considered "good" if, for every column, the sum of the elements in that column does not exceed half the size of the subset. Formally, if the subset conntains k rows, the sum of each column must be less than or equal to floor(k / 2). The goal is to return the indices of such a subse ...
Posted on Thu, 16 Jul 2026 16:05:53 +0000 by jsinker
Probability Expectation Problem for Collecting Trading Cards
A player collects trading cards with n distinct types. Each draw yields card type i with probability pi. Duplicate cards convert to coins, where k coins can be exchanged for one missing card. The process continues until all card types are collected. Compute the expected number of draws required.
Input Format
First line: n (card types) and k (co ...
Posted on Sat, 20 Jun 2026 16:29:23 +0000 by Bootsman123
Understanding Bloom Filters: Efficient Probabilistic Set Membership
Solving Cache Penetration
Consider a typical product lookup service:
public Product getProductById(Long id) {
Product product = cache.get(id);
if (product != null) {
return product;
}
product = database.query(id);
if (product != null) {
cache.put(id, product);
}
return product;
}
If a product ID ...
Posted on Sun, 24 May 2026 19:43:02 +0000 by facets
Bitmask Dynamic Programming Techniques
Bitmask Dynamic Programming (Bitmask DP) is a technique used to solve problems where the state of a system can be represented by a small set of binary flags. By using an integer's bits to store boolean information—where each bit corresponds to a specific element's status—we can compactly represent and manipulate complex configurations.
Core Con ...
Posted on Wed, 13 May 2026 20:34:02 +0000 by rhodry_korb