【题解】

  可以发现10的因数除了1和10之外只有2和5了,那么走过的路径上各个数字的2的因数个数之和、5的因数个数之和中较小的一个即是答案。这样的话DP即可。同时需要注意有0的情况,有0的时候有一个答案为1,要和前面求出的答案取较小值。

 #include<cstdio>
#include<algorithm>
#define LL long long
#define rg register
#define N 1010
using namespace std;
int n,m,px,py,tot,a[N][N],f[N][N],f2[N][N],exp2[N],exp5[N];
bool flag=;
struct rec{
int x,y;
}from[N][N],from2[N][N];
char ans[N<<];
inline int read(){
int k=,f=; char c=getchar();
while(c<''||c>'') c=getchar();
while(''<=c&&c<='')k=k*+c-'',c=getchar();
return k*f;
}
int main(){
n=read(); exp2[]=exp5[]=;
for(rg int i=;i<=;i++) exp2[i]=exp2[i-]<<;
for(rg int i=;i<=;i++) exp5[i]=exp5[i-]*;
for(rg int i=;i<=n;i++)
for(rg int j=;j<=n;j++){
a[i][j]=read();
if(!a[i][j]){
flag=; px=i; py=j; continue;
}
int tmp=a[i][j];
for(rg int k=;k;k--) if(tmp%exp2[k]==) f[i][j]+=k,tmp/=exp2[k];
while(tmp%==) f[i][j]++;
tmp=a[i][j];
for(rg int k=;k;k--) if(tmp%exp5[k]==) f2[i][j]+=k,tmp/=exp5[k];
while(tmp%==) f2[i][j]++;
// while(tmp%2==0){
// f[i][j]++;
// tmp>>=1;
// }
// tmp=a[i][j];
// while(tmp%5==0){
// f2[i][j]++;
// tmp/=5;
// }
}
for(rg int i=;i<=n;i++) f[i][]=f[][i]=f2[i][]=f2[][i]=2e9;
// f[1][0]=f[0][1]=f2[1][0]=f2[0][1]=0;
for(rg int i=;i<=n;i++)
for(rg int j=;j<=n;j++){
if(f[i-][j]<f[i][j-]){
from[i][j]=(rec){i-,j};
f[i][j]+=f[i-][j];
}
else{
from[i][j]=(rec){i,j-};
f[i][j]+=f[i][j-];
}
}
for(rg int i=;i<=n;i++)
for(rg int j=;j<=n;j++){
if(f2[i-][j]<f2[i][j-]){
from2[i][j]=(rec){i-,j};
f2[i][j]+=f2[i-][j];
}
else{
from2[i][j]=(rec){i,j-};
f2[i][j]+=f2[i][j-];
}
}
if(flag){
if(min(f[n][n],f2[n][n])>){
puts("");
for(rg int i=;i<=px;i++) putchar('D');
for(rg int i=;i<=py;i++) putchar('R');
for(rg int i=px+;i<=n;i++) putchar('D');
for(rg int i=py+;i<=n;i++) putchar('R');
return ;
}
}
printf("%d\n",min(f[n][n],f2[n][n]));
if(f[n][n]<f2[n][n]){
int nx=n,ny=n;
while(){
int fx=from[nx][ny].x,fy=from[nx][ny].y;
if(fx==||fy==) break;
if(fx<nx) ans[++tot]='D';
else ans[++tot]='R';
nx=fx; ny=fy;
if(fx==&&fy==) break;
}
}
else{
int nx=n,ny=n;
while(){
int fx=from2[nx][ny].x,fy=from2[nx][ny].y;
if(fx==||fy==) break;
if(fx<nx) ans[++tot]='D';
else ans[++tot]='R';
nx=fx; ny=fy;
if(fx==&&fy==) break;
}
}
for(rg int i=tot;i;i--) putchar(ans[i]);
// puts("");
// for(rg int i=1;i<=n;i++){
// for(rg int j=1;j<=n;j++) printf("[%d %d] ",from2[i][j].x,from2[i][j].y);
// puts("");
// }
return ;
}

CF2B The least round way的更多相关文章

  1. CF2B The least round way(贪心+动规)

    题目 CF2B The least round way 做法 后面\(0\)的个数,\(2\)和\(5\)是\(10\)分解质因数 则把方格中的每个数分解成\(2\)和\(5\),对\(2\)和\(5 ...

  2. CF2B The least round way(dp+记录路径)

    B. The least round way time limit per test 2 seconds memory limit per test 64 megabytes input standa ...

  3. CF2B The least round way 题解

    都是泪呀...↑ 题目传送门 题意(直接复制了QWQ) 题目描述 给定由非负整数组成的\(n \times n\)的正方形矩阵,你需要寻找一条路径: 以左上角为起点, 每次只能向右或向下走, 以右下角 ...

  4. [CF2B] The least round way - dp

    给定由非负整数组成的n×n 的正方形矩阵,你需要寻找一条路径: 以左上角为起点 每次只能向右或向下走 以右下角为终点 并且,如果我们把沿路遇到的数进行相乘,积应当是最小"round" ...

  5. SQL Server 随机数,随机区间,随机抽取数据rand(),floor(),ceiling(),round(),newid()函数等

    在查询分析器中执行:select rand(),可以看到结果会是类似于这样的随机小数:0.36361513486289558,像这样的小数在实际应用中用得不多,一般要取随机数都会取随机整数.那就看下面 ...

  6. SQL中Round(),Floor(),Ceiling()函数的浅析

    项目中的一个功能模块上用到了标量值函数,函数中又有ceiling()函数的用法,自己找了一些资料,对SQL中这几个函数做一个简单的记录,方便自己学习.有不足之处欢迎拍砖补充 1.round()函数遵循 ...

  7. oracle的round函数和trunc函数

    --Oracle trunc()函数的用法/**************日期********************/1.select trunc(sysdate) from dual --2013- ...

  8. Codeforces Round #366 (Div. 2) ABC

    Codeforces Round #366 (Div. 2) A I hate that I love that I hate it水题 #I hate that I love that I hate ...

  9. Codeforces Round #354 (Div. 2) ABCD

    Codeforces Round #354 (Div. 2) Problems     # Name     A Nicholas and Permutation standard input/out ...

随机推荐

  1. Vue.js实战 5.5章 购物车

    <!DOCTYPE html> <html lang="en"> <head> <title>购物车示例</title> ...

  2. bzoj 1670: [Usaco2006 Oct]Building the Moat护城河的挖掘【凸包】

    凸包模板 #include<iostream> #include<cstdio> #include<algorithm> #include<cmath> ...

  3. P2973 [USACO10HOL]赶小猪

    跟那个某省省选题(具体忘了)游走差不多... 把边搞到点上然后按套路Gauss即可 貌似有人说卡精度,$eps≤1e-13$,然而我$1e-12$也可以过... 代码: #include<cst ...

  4. Juicer.js模板引擎问题

    由于jsp中的EL表达式语法和jquery.tmpl十分类似,,所以单纯的使用${name},数据是渲染不上tmpl的. SO.. 要加上转义: ${'${'}amount} 或者 \${amount ...

  5. jsonp 监控简陋代码

    url: window.location.href Agent: navigator.userAgent var tkInfo = { VisitUrl: window.location.href, ...

  6. [转]URL最大长度问题

    本文转自:http://www.cnblogs.com/henryhappier/archive/2010/10/09/1846554.html 今天在测试Email Ticket的时候发现在进行Ma ...

  7. python中os模块中文帮助

    python中os模块中文帮助   python中os模块中文帮助文档文章分类:Python编程 python中os模块中文帮助文档 翻译者:butalnd 翻译于2010.1.7——2010.1.8 ...

  8. hexo博客域名重复提交问题

    之前电脑重装系统,导致我的博客也忘记备份了.呜呜 期间试过hexo的next主题,虽然很好看,但是一直出问题,最终又恢复到了原来的主题,还是原来的配方,还是原来的味道 记录: 一.加载域名管理器 二. ...

  9. Burp Suite抓https数据包

    本地环境JDK1.8Burp Suite 1.7.26 Firefox 59.0.2 一.burp介绍请自行谷歌,这里不过多介绍 二.配置HTTPS抓包方法[以Firefox为例]通常情况下burp默 ...

  10. python自动化--接口请求及封装

    基于http协议,最常用的是GET和POST两种方法. 接口文档需要包含哪些信息: 接口名称接口功能接口地址支持格式 json/xml请求方式请求示例请求参数(是否必填.数据类型.传递参数格式)返回参 ...