Codeforces #2B The least round way(DP)
Description
有一個n*n的正整數矩陣,要你求一條從第一行第一列的格子到第n行第n列的路,使得你走過的格子裡面的數乘起來的值末尾的零的個數最小。輸出最小個數。
Input
第一行包含1個數n。
接下來n行每行n個數字。
Output
一個數字表示末尾零最小個數。
Sample Input
3
1 2 3
4 5 6
7 8 9
Sample Output
0
由於都是正數,對這個來說只需統計最少的2或5即可。相對簡單。
#include
#include
#include
#include
#include
#include
#include
#include
#include
再看Codeforces 2B:
Description
There is a square matrix n?×?n, consisting of non-negative integer numbers. You should find such a way on it that
starts in the upper left cell of the matrix;each following cell is to the right or down from the current cell;the way ends in the bottom right cell.
Moreover, if we multiply together all the numbers along the way, the result should be the least "round". In other words, it should end in the least possible number of zeros.
Input
The first line contains an integer number n (2?≤?n?≤?1000), n is the size of the matrix. Then follow n lines containing the matrix elements (non-negative integer numbers not exceeding109).
Output
In the first line print the least number of trailing zeros. In the second line print the correspondent way itself.
Sample Input
Input
3
1 2 3
4 5 6
7 8 9
Output
0
DDRR
Source
不僅要輸出路徑,而且矩陣中還帶了0,這就是麻煩的地方;
題解:對於要輸出的路徑,記錄前面的一個狀態即可,對於0的處理,如果到終點的2或
5的個數大於等於1了,而矩陣中含0,這時候就是直接答案就是1個0,路徑只需找到任意
一個0所在的行列輸出即可。
#include
#include
#include
#include
#include
#include
#include
#include
#include