【动态规划】The least round way

给定一个非负整数矩阵,找到一条从左上角到右下角的路径,使得路径上的数字乘积的末尾零最少。输出末尾零的个数以及对应的路径。
摘要由CSDN通过智能技术生成

B. The least round way
time limit per test5 seconds
memory limit per test64 megabytes
inputstandard input
outputstandard output
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 exceeding 109).

Output
In the first line print the least number of trailing zeros. In the second line print the correspondent way itself.

Sample test(s)
input
3
1 2 3
4 5 6
7 8 9
output
0
DDRR

#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;

int a[1003][1003];
char path[2003];

void judge(int &x2, int &x5, int n)
{
    x2 = x5 = 0;
    while(n % 5 == 0 && n)
    {
        n /= 5;
        x5++;
    }
    while(n % 2 == 0 && n)
    {
        n /= 2;
        x2++;
    }
}

struct Node
{
    int Susake2;
    int Susake5;
    int px, py;
};

Node Susake[1003][1003], dp1[1003][1003], dp2[1003][1003];

int main(int argc, char *argv[])
{
    int n

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值