2B The least round way
题目大意:
#include <iostream>
#include <cmath>
#include <algorithm>
#include <string>
#include <cstring>
#include <cstdio>
#include <vector>
#include <cstdlib>
using namespace std;
typedef long long LL;
const LL INF = 0xffffff;
const int maxn = ;
const LL MOD = 1e9+;
struct node
{
int num2, num5;
} dp2[maxn][maxn], dp5[maxn][maxn], a[maxn][maxn];
int K[maxn][maxn], n; bool HaveZero(int& x,int& y)
{
for(int i=; i<=n; i++)
{
for(int j=; j<=n; j++)
{
if(K[i][j] == )
{
x = i;
y = j;
return true;
}
}
}
return false;
} void PutPath5(int x,int y)
{
if(x == && y == )
return;
if(dp5[x][y].num2 == dp5[x-][y].num2 + a[x][y].num2 && dp5[x][y].num5 == dp5[x-][y].num5 + a[x][y].num5)
{
PutPath5(x-, y);
printf("D");
}
else
{
PutPath5(x, y-);
printf("R"); }
} void PutPath2(int x,int y)
{
if(x == && y == )
return;
if( dp2[x][y].num2 == dp2[x-][y].num2 + a[x][y].num2 && dp2[x][y].num5 == dp2[x-][y].num5 + a[x][y].num5)
{
PutPath2(x-, y);
printf("D");
}
else
{
PutPath2(x, y-);
printf("R");
}
} void PutPath()
{
int x, y;
int ans = min( min(dp2[n][n].num2,dp2[n][n].num5) , min(dp5[n][n].num2,dp5[n][n].num5) );
if( HaveZero(x,y) && ans > )
{
printf("1\n");
for(int i=; i<=x; i++)
printf("D");
for(int i=; i<=y; i++)
printf("R");
for(int i=x+; i<=n; i++)
printf("D");
for(int i=y+; i<=n; i++)
printf("R");
return ;
}
if( min(dp2[n][n].num2,dp2[n][n].num5) < min(dp5[n][n].num2,dp5[n][n].num5) )
{
printf("%d\n", min(dp2[n][n].num2,dp2[n][n].num5));
PutPath2(n, n);
}
else
{
printf("%d\n", min(dp5[n][n].num2,dp5[n][n].num5));
PutPath5(n, n);
} } void Process(int i,int j,int p)
{
int k = p;
while(k)
{
if(k% == )
a[i][j].num2 ++;
else
break;
k /= ;
}
k = p;
while(k)
{
if(k% == )
a[i][j].num5 ++;
else
break;
k /= ;
}
}
int main()
{
cin >> n;
for(int i=; i<=n; i++)
for(int j=; j<=n; j++)
{
scanf("%d", &K[i][j]);
Process(i, j, K[i][j]);
} for(int i=; i<=n; i++)
{
dp2[i][].num5 = dp2[i][].num2 = dp2[][i].num2 = dp2[][i].num5 = INF;
dp5[i][].num5 = dp5[i][].num2 = dp5[][i].num2 = dp5[][i].num5 = INF;
a[][i].num2 = a[][i].num5 = a[i][].num2 = a[i][].num5 = INF;
}
for(int i=; i<=n; i++)
for(int j=; j<=n; j++)
{
dp2[i][j] = a[i][j];
dp5[i][j] = a[i][j];
if(dp2[i-][j].num2 > dp2[i][j-].num2 && j->)
{
dp2[i][j].num2 += dp2[i][j-].num2 ;
dp2[i][j].num5 += dp2[i][j-].num5 ;
}
else if(i- > )
{
dp2[i][j].num2 += dp2[i-][j].num2;
dp2[i][j].num5 += dp2[i-][j].num5;
} if(dp5[i-][j].num5 > dp5[i][j-].num5 && j->)
{
dp5[i][j].num2 += dp5[i][j-].num2;
dp5[i][j].num5 += dp5[i][j-].num5;
}
else if(i- > )
{
dp5[i][j].num2 += dp5[i-][j].num2 ;
dp5[i][j].num5 += dp5[i-][j].num5 ;
}
} PutPath();
printf("\n");
return ;
}
2B The least round way的更多相关文章
- Codeforces #2B The least round way(DP)
Description 有一个n*n的正整数矩阵,要你求一条从第一行第一列的格子到第n行第n列的路,使得你走过的格子里面的数乘起来的值末尾的零的个数最小.输出最小个数. Input 第一行包括1个数n ...
- Codeforces 2B. The least round way
There is a square matrix n × n, consisting of non-negative integer numbers. You should find such a w ...
- codeforces 2B The least round way(DP+数学)
The least round way 题目链接:http://codeforces.com/contest/2/problem/B ——每天在线,欢迎留言谈论.PS.本题有什么想法.建议.疑问 欢迎 ...
- CF 2B.The least round way
题目链接 很久以前就见过此题,以前看了题解,然后今天写了写,写的真搓. #include <cstdio> #include <cstring> #include <st ...
- codeforces 2B The least round way 【DP】
VJ上可找到中文题意. 思路: 首先分解有多少2与多少5.接下来就是dp. 分两次,一次是根据2的数量贪心,另外一次是根据5的数量贪心,看哪一次乘积的末尾0最少. 需要注意的是两点: 1.输入有0的情 ...
- 最小较小codeforces 2B The least round way
查了好多资料,发现还是不全,干脆自己整理吧,至少保证在我的做法正确的,以免误导读者,也是给自己做个记载吧! 求从左上角到右下角所经过的数字之积末端所含0最小的个数 终究的积可以当作A*2^x*5^y, ...
- CF 2B The least round way DP+Math
题意: 找出一条路, 使每个节点相乘,得到的数末尾 0 最少 每次移动只能向右或者向下, 找到后打印路径 ///按照题目要求,就是找出一条从左上角到右下角中每个数含2 or 5 最少的路 ///可以用 ...
- Codeforces 2B The least round way(dp求最小末尾0)
题目链接:http://codeforces.com/problemset/problem/2/B 题目大意: 给你一个nxn的矩形,找到一条从左上角到右下角的路径,使得该路径上所有数字的乘积的末尾0 ...
- CF dp 题(1500-2000难度)
前言 从后往前刷 update 新增 \(\text{\color{red}{Mark}}\) 标记功能,有一定难度的题标记为 \(\text{\color{red}{红}}\) 色. 题单 (刷过的 ...
随机推荐
- 【转载】ASP.NET支持多语言
ASP.NET 2.0中实现:1.使用工具自动生成本地化资源(LocalResources) 首先建立一个WEB工程,如图所示:双击Default.aspx,切换到[设计]视图,从工具箱里拖一个But ...
- 关于this 的一个问题
var name = "the window"; var object = { name:"my object"; getName:function(){ re ...
- WinForm中的事件触发机制学习
在一个Form窗体中拖个按钮,双击后系统自动生成代码: private void button1_Click(object sender, EventArgs e) { } 同时在窗体的Initial ...
- ubuntu JDK
第一步:下载jdk-7-linux-i586.tar.gz 第二步:解压安装 cd /usr/libsudo mkdir jvm cd {你的目录jdk压缩文件目录} sudo tar zxvf jd ...
- SpringMVC4+thymeleaf3的一个简单实例(篇四:form表单数据验证)
关于表单数据验证有很多中方法,这里我仅介绍JSR303注解验证.JSR303仅仅是一个规范,这里我们要用到它的一个实现:hibernate-validator. 注意在spring的配置文件sprin ...
- Spring 创建bean的模式
在默认情况下,spring创建bean是单例模式 scope="singleton ",还有一种方式为多例模式[prototype] scope sing ...
- APP被Rejected 的各种原因翻译(转)
原文:http://www.cnblogs.com/sell/archive/2013/02/16/2913341.html Terms and conditions(法律与条款) 1.1 As a ...
- 借助Q.js学习javascript异步编程。
金字塔式 //add1 function step1(n, callback) { setTimeout(function(){ callback.call(null, n + 1); }, 100) ...
- 熄灯问题 --POJ 2811-ACM
问题描述 盏灯的状态. 列的灯的状态就不改变. 请你写一个程序,确定需要按下哪些按钮,恰好使得所有的灯都熄灭.根据上面的规则,我们知道: 次按下时所产生的结果.因此,每个按钮最多只需要按下一次: (2 ...
- Swiper的简单实用方法
最近项目中有用到一个非常强大的组件idangerous.swiper.js的组件,这个组件能够实现幻灯片的播放效果,而且有各种3D效果,大家可以去试一下,效果很不错的说! 这是这个项目的api文档:h ...