次元 m X n のコスト マトリックスが与えられます。問題は、左上隅からマトリックス内のセルまでの最小パスを見つけることです。パスの総コストは、パスでアクセスしたすべてのセルのコストの合計です。 .行ごとに下に移動するか、列ごとに右に移動するかの 2 つの移動のみが許可されます。いつでもマトリックスを離れることはできません。また、一部のセルは障害物としてマークされており、踏むことができません。tx ty k という形式のいくつかのクエリに回答する必要があります。このクエリの出力は、左上隅から tx 行の ty 列でインデックス付けされたセルまでのパスの k 番目の最小コストである必要があります。
1<= m,n <= 100 0 <= tx < m 0 <= ty <n 1 <= k <= 101
The obstacles in matrix are marked by "##" (quotes only for clarity)
The values in every cell that is not an obstacle, varies from -9 to 99 only.
tx and ty are both 0-indexed.
If k exceeds the total paths to cell (tx, ty) output "Not so many paths"
If (tx, ty) is an obstacle, output "Obstacle".
There will never be an obstacle on the top-left corner or bottom-right corner.
Input:
The first line contains the number of test cases T,
The first line of each test case contains two space-separated integers m and n.
The next m lines each contain n integers, denoting the matrix.
The next line contains an integer q, denoting the number of queries to come.
The next q lines each contain 3 space separated integers, tx ty and k
Output:
For each query output the kth shortest path
私が試したのは、バックトラッキングであり、TLE が発生しました (制限時間は 1 秒でした)。宛先セルに到達するたびに、そのパス コストをベクトルに格納し、最後にベクトルを並べ替えた後、K 番目の値をベクトルに出力しました。 .しかし、問題を解決するためのより効率的な方法が必要です..ここで動的計画法を使用できますか..???