You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
30 lines
720 B
30 lines
720 B
2 years ago
|
type LS = Vec<Vec<Option<u64>>>;
|
||
|
|
||
|
struct Lattice { ls: LS }
|
||
|
|
||
|
impl Lattice {
|
||
|
pub fn new() -> Lattice {
|
||
|
let mut ls = LS::new();
|
||
|
for _i in 0..21 {
|
||
|
let lr = vec![None; 21];
|
||
|
ls.push(lr);
|
||
|
}
|
||
|
ls[0][0] = Some(1);
|
||
|
Lattice { ls: ls }
|
||
|
}
|
||
|
pub fn compute(&mut self, i: usize, j: usize) -> u64 {
|
||
|
if self.ls[i][j].is_some() { return self.ls[i][j].unwrap(); }
|
||
|
let mut res = 0u64;
|
||
|
if i > 0 { res += self.compute(i - 1, j); }
|
||
|
if j > 0 { res += self.compute(i, j - 1); }
|
||
|
self.ls[i][j] = Some(res);
|
||
|
res
|
||
|
}
|
||
|
}
|
||
|
|
||
|
fn main() {
|
||
|
let mut lt = Lattice::new();
|
||
|
let res = lt.compute(20, 20);
|
||
|
println!("{}", res);
|
||
|
}
|