1 unstable release

0.1.0 Jun 27, 2019

#2400 in Data structures

Download history 350/week @ 2024-04-05 255/week @ 2024-04-12 276/week @ 2024-04-19 233/week @ 2024-04-26 260/week @ 2024-05-03 262/week @ 2024-05-10 221/week @ 2024-05-17 249/week @ 2024-05-24 263/week @ 2024-05-31 155/week @ 2024-06-07 194/week @ 2024-06-14 223/week @ 2024-06-21 137/week @ 2024-06-28 76/week @ 2024-07-05 146/week @ 2024-07-12 201/week @ 2024-07-19

597 downloads per month
Used in 3 crates

MIT license

13KB
378 lines

bitset-fixed

Bitset for DP.

Example

Example for AGC20-C

use bitset_fixed::BitSet;
use rand::prelude::*;

fn main() {
    let mut rng = StdRng::seed_from_u64(114514);

    let n: Vec<usize> = (0..25).map(|_| rng.next_u32() as usize % 2000).collect();
    let sum = n.iter().sum::<usize>();

    let mut bitset = BitSet::new(sum + 1);
    bitset.set(0, true);

    for &x in &n {
        bitset |= &(&bitset << x);
    }

    let ans = ((sum + 1) / 2..).find(|&i| bitset[i]).unwrap();

    println!("N = {:?}\nAnswer = {}", n, ans);
}

No runtime deps