AC 042, started from the beginning of atcoder with rust to practice my rust
This commit is contained in:
43
atcoder/beginner_contests/abc042/src/bin/d.rs
Normal file
43
atcoder/beginner_contests/abc042/src/bin/d.rs
Normal file
@@ -0,0 +1,43 @@
|
||||
use proconio::input;
|
||||
|
||||
const MAX: u128 = u128::pow(10, 9) + 7;
|
||||
|
||||
fn main() {
|
||||
input!{
|
||||
h: u128,
|
||||
w: u128,
|
||||
a: u128,
|
||||
b: u128,
|
||||
};
|
||||
|
||||
// Ok it seems like this way is too naive for this problem and I actually have
|
||||
// to do some magic with combinations or something else I haven't even thought of
|
||||
|
||||
// But I don't think you can do combinations because you need to divide big numbers
|
||||
// and you can't do that with modulo iirc
|
||||
|
||||
let mut dp = vec![vec![0; w as usize]; h as usize];
|
||||
for i in 0..(h-a) {
|
||||
dp[i as usize][0] = 1;
|
||||
}
|
||||
for j in 0..w {
|
||||
dp[0][j as usize] = 1;
|
||||
}
|
||||
|
||||
for i in 1..h {
|
||||
for j in 1..w {
|
||||
if !(i >= h - a && j < b) {
|
||||
dp[i as usize][j as usize] = (dp[(i - 1) as usize][j as usize] + dp[i as usize][(j - 1) as usize]) % MAX;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// for row in &dp {
|
||||
// for cell in row {
|
||||
// print!("{} ", {cell});
|
||||
// }
|
||||
// print!("\n");
|
||||
// }
|
||||
|
||||
println!("{}", {dp[(h-1) as usize][(w-1) as usize]});
|
||||
}
|
||||
Reference in New Issue
Block a user