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}{红}}\) 色. 题单 (刷过的 ...
随机推荐
- Java基础知识强化之集合框架笔记17:List集合的特有的遍历功能
1. List集合的特有遍历功能: size()和 get()方法结合使用 2. 代码示例: package cn.itcast_03; import java.util.ArrayList; imp ...
- 11.3 morning
noip模拟题day1 总览(Overview) 题目名称 取模 等比数列 回文串 程序名 mod sequence palindromes 输入文件名 mod.in sequence.in pa ...
- Premature optimization is the root of all evil.
For all of we programmers,we should always remember that "Premature optimization is the root of ...
- xceed wpf datagrid
<!--*********************************************************************************** Extended ...
- 向RichTextBox控件不停的AppendText数据时,如何把光标的焦点始终显示到最后
上面是csdn上的一个网友的问题,我的一个实现如下://让文本框获取焦点this.richTextBoxInfo.Focus();//设置光标的位置到文本尾this.richTextBoxInfo.S ...
- spring-quartz普通任务与可传参任务
两者区别与作用: 普通任务:总调度(SchedulerFactoryBean)--> 定时调度器(CronTriggerFactoryBean) --> 调度明细自定义执行方法bean(M ...
- 【转】ThinkPHP中数据库操作返回值总结
Thinkphp中的Think\Model类提供了数据库的基本CURD(Create.Update.Read及Delete),通过该类可以很便捷的进行操作.Model类及扩展类主要的方法有: Crea ...
- 【技术宅4】如何把M个苹果平均分给N个小朋友
$apple=array('apple1','apple2','apple3','apple4','apple5','apple6','apple7','apple8','apple9','apple ...
- Android获取相册图片
1. AlertDialog的使用 2. 显示和隐式意图的区别 3. 相册页面的跳转 4. 选择完成后返回图片的获取 ----------------------------------------- ...
- 不让input表单的输入框保存用户输入的历史记录
如何不让input表单的输入框保存用户输入的历史记录. 有时我们在设计网页时不想让表单保存用户输入历史记录,比如一些隐私数据,或一些冲值卡 <input name="test&quo ...