Geeksforgeeks

Error

×

Leaderboard

Showing:

Handle | Score |
---|---|

@Ibrahim Nash | 5761 |

@blackshadows | 5715 |

@akhayrutdinov | 5111 |

@mb1973 | 4989 |

@Quandray | 4944 |

@saiujwal13083 | 4506 |

@sanjay05 | 3762 |

@marius_valentin_dragoi | 3516 |

@sushant_a | 3459 |

@verma_ji | 3341 |

@KshamaGupta | 3318 |

Complete Leaderboard | |

Handle | Score |

@aroranayan999 | 1083 |

@bt8816103042 | 739 |

@SherlockHolmes3 | 444 |

@SHOAIBVIJAPURE | 430 |

@codeantik | 429 |

@shalinibhataniya1097 | 400 |

@ShamaKhan1 | 376 |

@neverevergiveup | 372 |

@amrutakashikar2 | 355 |

@murarry3625 | 350 |

@mahlawatep | 349 |

Complete Leaderboard |

Given a **N x N** matrix where every cell has some number of coins. Count number of ways to reach bottom right cell of matrix from top left cell with exactly **K** coins. We can move to (i+1, j) or (i, j+1) from a cell (i, j).

**Input:**

First line contains number of test cases T. For each test case, first line contains the integer value '**X**' denoting coins, second line contains an integer 'N' denoting the order of square matrix. Last line contains N x N elements in a single line in row-major order.

**Output:**

Output the number of paths possible.

**Constraints:**

1 <=T<= 500

1 <= K <= 200

1 <= N <= 200

1 <= A_{i} <= 200

**Example:
Input:**

2

16

3

1 2 3 4 6 5 9 8 7

12

3

1 2 3 4 6 5 3 2 1

**Output:**

0

2

**Explanation:**

**Testcase 2:** There are 2 possible paths with exactly K coins, which are (1 + 4 + 3 + 2 + 1) and (1 + 2 + 3 + 5 + 1).

Login to report an issue on this page.

We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?

Yes
Number of paths in a matrix with k coins

...