3393. Count Paths With the Given XOR Value Medium

@problem@discussion
#Array#Dynamic Programming#Bit Manipulation#Matrix



1/**
2 * [3393] Count Paths With the Given XOR Value
3 *
4 * You are given a 2D integer array grid with size m x n. You are also given an integer k.
5 * Your task is to calculate the number of paths you can take from the top-left cell (0, 0) to the bottom-right cell (m - 1, n - 1) satisfying the following constraints:
6 * 
7 * 	You can either move to the right or down. Formally, from the cell (i, j) you may move to the cell (i, j + 1) or to the cell (i + 1, j) if the target cell exists.
8 * 	The XOR of all the numbers on the path must be equal to k.
9 * 
10 * Return the total number of such paths.
11 * Since the answer can be very large, return the result modulo 10^9 + 7.
12 *  
13 * <strong class="example">Example 1:
14 * <div class="example-block">
15 * Input: <span class="example-io">grid = [[2, 1, 5], [7, 10, 0], [12, 6, 4]], k = 11</span>
16 * Output: <span class="example-io">3</span>
17 * Explanation: 
18 * The 3 paths are:
19 * 
20 * 	(0, 0) &rarr; (1, 0) &rarr; (2, 0) &rarr; (2, 1) &rarr; (2, 2)
21 * 	(0, 0) &rarr; (1, 0) &rarr; (1, 1) &rarr; (1, 2) &rarr; (2, 2)
22 * 	(0, 0) &rarr; (0, 1) &rarr; (1, 1) &rarr; (2, 1) &rarr; (2, 2)
23 * </div>
24 * <strong class="example">Example 2:
25 * <div class="example-block">
26 * Input: <span class="example-io">grid = [[1, 3, 3, 3], [0, 3, 3, 2], [3, 0, 1, 1]], k = 2</span>
27 * Output: <span class="example-io">5</span>
28 * Explanation:
29 * The 5 paths are:
30 * 
31 * 	(0, 0) &rarr; (1, 0) &rarr; (2, 0) &rarr; (2, 1) &rarr; (2, 2) &rarr; (2, 3)
32 * 	(0, 0) &rarr; (1, 0) &rarr; (1, 1) &rarr; (2, 1) &rarr; (2, 2) &rarr; (2, 3)
33 * 	(0, 0) &rarr; (1, 0) &rarr; (1, 1) &rarr; (1, 2) &rarr; (1, 3) &rarr; (2, 3)
34 * 	(0, 0) &rarr; (0, 1) &rarr; (1, 1) &rarr; (1, 2) &rarr; (2, 2) &rarr; (2, 3)
35 * 	(0, 0) &rarr; (0, 1) &rarr; (0, 2) &rarr; (1, 2) &rarr; (2, 2) &rarr; (2, 3)
36 * </div>
37 * <strong class="example">Example 3:
38 * <div class="example-block">
39 * Input: <span class="example-io">grid = [[1, 1, 1, 2], [3, 0, 3, 2], [3, 0, 2, 2]], k = 10</span>
40 * Output: <span class="example-io">0</span>
41 * </div>
42 *  
43 * Constraints:
44 * 
45 * 	1 <= m == grid.length <= 300
46 * 	1 <= n == grid[r].length <= 300
47 * 	0 <= grid[r][c] < 16
48 * 	0 <= k < 16
49 * 
50 */
51pub struct Solution {}
52
53// problem: https://leetcode.com/problems/count-paths-with-the-given-xor-value/
54// discuss: https://leetcode.com/problems/count-paths-with-the-given-xor-value/discuss/?currentPage=1&orderBy=most_votes&query=
55
56// submission codes start here
57
58impl Solution {
59    pub fn count_paths_with_xor_value(grid: Vec<Vec<i32>>, k: i32) -> i32 {
60        0
61    }
62}
63
64// submission codes end
65
66#[cfg(test)]
67mod tests {
68    use super::*;
69
70    #[test]
71    fn test_3393() {
72    }
73}
74


Back
© 2025 bowen.ge All Rights Reserved.