BuringStraw

BuringStraw

Introduction to Compressed Dynamic Programming

Introduction to State Compression DP#

So, state compression is about putting a bunch of consecutive states that can be represented by 01 into an integer, and then using bitwise operations to perform checks, transitions, and other operations.

Example Problem#

[SCOI2005] Non-Interference

The distribution of kings in each row can be represented by 01, so the state of each row can be represented by an integer.

First, preprocess all the situations in a row where there are no fights, and the corresponding number of kings in that situation.

f[i][j][k] represents the number of solutions where the state of the ith row is the jth kind and k kings are used.

See the code for details.

This time I used nodejs to write, and after finishing it, I suddenly felt that c++ is the best language.

Code#

Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.