1 unstable release

0.1.0 Jun 27, 2019

#2678 in Data structures

Download history 174/week @ 2024-08-31 133/week @ 2024-09-07 128/week @ 2024-09-14 120/week @ 2024-09-21 129/week @ 2024-09-28 107/week @ 2024-10-05 133/week @ 2024-10-12 113/week @ 2024-10-19 113/week @ 2024-10-26 130/week @ 2024-11-02 55/week @ 2024-11-09 84/week @ 2024-11-16 138/week @ 2024-11-23 136/week @ 2024-11-30 247/week @ 2024-12-07 351/week @ 2024-12-14

887 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