Coin de Gamma
2 years ago
1 changed files with 29 additions and 0 deletions
@ -0,0 +1,29 @@
|
||||
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); |
||||
} |
Loading…
Reference in new issue