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.
#include<bits/stdc++.h> usingnamespace std; #define int long long inlineintread(){int x=0,f=1;char ch=getchar(); while(ch<'0'||ch>'9'){if(ch=='-')f=-1; ch=getchar();}while(ch>='0'&&ch<='9'){x=(x<<1)+ (x<<3)+(ch^48);ch=getchar();}return x*f;} //#define M //#define mo #define N 1010 int n, m, i, j, k; int a[N][N], dp[N][N][2], f[N][N][2], ans;
voiddfs(int x, int y, int k) { // printf("%d %d %d\n", x, y, k); // if(x==1||y==1) return ; // if(x==1&&y==1) return ; if(f[x][y][k]==1) dfs(x, y-1, k), putchar('R'); if(f[x][y][k]==-1) dfs(x-1, y, k), putchar('D'); }