Codeforces Beta Round #2B(dp+数学)
贡献了一列WA。。
数学很神奇啊
这个题的关键是怎么才能算尾0的个数 只能相乘 可以想一下所有一位数相乘 除0之外,只有2和5相乘才能得到0 当然那些本身带0的多位数 里面肯定含有多少尾0 就含有多少对2和5
这样就知道了 就是求2和5 的对数最少的 一条路 DP就不用说了 递推
注意有0的时候的计算 特殊处理一下

#include <iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<stdlib.h>
#include<vector>
using namespace std;
#define N 1010
#define INF 1e10
#define LL __int64
LL dp[N][N][];
int a[N][N],b[N][N];
int n;
char pa[N<<];
int init(int x,int k)
{
int num=;
while(x)
{
if(x%k==)
{
num++;
x/=k;
}
else break;
}
return num;
}
int main()
{
int i,j,y,o1,o2,f=;
scanf("%d",&n);
for(i = ; i <= n ; i++)
for(j = ; j <= n ; j++)
{
scanf("%d",&y);
if(y==)
{
o1 = i;
o2 = j;
f = ;
}
int o = init(y,);
a[i][j] = o;
o = init(y,);
b[i][j] = o;
}
for(i = ; i <= n; i++)
for(j = ; j <= n ; j++)
{
dp[i][j][] = INF;
dp[i][j][] = INF;
}
dp[][][] = a[][];
dp[][][] = b[][];
for(i = ; i <= n ; i++)
for(j = ; j <= n ; j++)
{
dp[i][j][] = min(dp[i][j][],min(dp[i-][j][],dp[i][j-][])+a[i][j]);
dp[i][j][] = min(dp[i][j][],min(dp[i-][j][],dp[i][j-][])+b[i][j]);
}
int g = ;
if(f&&min(dp[n][n][],dp[n][n][])>)
{
printf("1\n");
for(i = ; i < o2 ; i++)
printf("R");
for(i = ; i < o1 ; i++)
printf("D");
for(i = o2; i < n ; i++)
printf("R");
for(i = o1; i < n ; i++)
printf("D");
return ;
}
if(dp[n][n][]<dp[n][n][])
{
int i = n,j = n;
while()
{
if(i>&&dp[i][j][]==dp[i-][j][]+a[i][j])
{
i = i-;
pa[++g] = 'D';
}
else if(j>)
{
j = j-;
pa[++g] = 'R';
}
if(i==&&j==)
break;
}
}
else
{
int i = n,j = n;
while()
{
if(i>&&dp[i][j][]==dp[i-][j][]+b[i][j])
{
i = i-;
pa[++g] = 'D';
}
else if(j>)
{
j = j-;
pa[++g] = 'R';
}
if(i==&&j==)
break;
}
}
printf("%I64d\n",min(dp[n][n][],dp[n][n][]));
for(i = g ; i >= ; i--)
printf("%c",pa[i]);
puts("");
return ;
}
Codeforces Beta Round #2B(dp+数学)的更多相关文章
- 暴力/DP Codeforces Beta Round #22 (Div. 2 Only) B. Bargaining Table
题目传送门 /* 题意:求最大矩形(全0)的面积 暴力/dp:每对一个0查看它左下的最大矩形面积,更新ans 注意:是字符串,没用空格,好事多磨,WA了多少次才发现:( 详细解释:http://www ...
- Codeforces Beta Round #16 E. Fish (状压dp)(概率dp)
Codeforces Beta Round #16 (Div. 2 Only) E. Fish 题目链接:## 点击打开链接 题意: 有 \(n\) 条鱼,每两条鱼相遇都会有其中一只吃掉对方,现在给你 ...
- Codeforces Beta Round #13 C. Sequence (DP)
题目大意 给一个数列,长度不超过 5000,每次可以将其中的一个数加 1 或者减 1,问,最少需要多少次操作,才能使得这个数列单调不降 数列中每个数为 -109-109 中的一个数 做法分析 先这样考 ...
- Codeforces Beta Round #62 题解【ABCD】
Codeforces Beta Round #62 A Irrational problem 题意 f(x) = x mod p1 mod p2 mod p3 mod p4 问你[a,b]中有多少个数 ...
- Codeforces Beta Round #83 (Div. 1 Only)题解【ABCD】
Codeforces Beta Round #83 (Div. 1 Only) A. Dorm Water Supply 题意 给你一个n点m边的图,保证每个点的入度和出度最多为1 如果这个点入度为0 ...
- Codeforces Beta Round #77 (Div. 2 Only)
Codeforces Beta Round #77 (Div. 2 Only) http://codeforces.com/contest/96 A #include<bits/stdc++.h ...
- Codeforces Beta Round #67 (Div. 2)
Codeforces Beta Round #67 (Div. 2) http://codeforces.com/contest/75 A #include<bits/stdc++.h> ...
- Codeforces Beta Round #59 (Div. 2)
Codeforces Beta Round #59 (Div. 2) http://codeforces.com/contest/63 A #include<bits/stdc++.h> ...
- Codeforces Beta Round #52 (Div. 2)
Codeforces Beta Round #52 (Div. 2) http://codeforces.com/contest/56 A #include<bits/stdc++.h> ...
随机推荐
- 从InputStream到String_写成函数
String result = readFromInputStream(inputStream);//调用处 //将输入流InputStream变为String public String readF ...
- ora-28002 the password will expire解决办法
Oracle11g R2数据库提示ORA-28002: the password will expire within 5 days,是说密码过期,将Oracle密码设置成永不过期就可以了,不过并不推 ...
- Machine Learning Done Wrong
Machine Learning Done Wrong Statistical modeling is a lot like engineering. In engineering, there ar ...
- win8 任务栏不合并隐藏标题
让win8任务栏不合并,并且隐藏标题的办法: 效果如下: 首先让win8不合并任务栏 1.任务栏上点鼠标右键 -- "属性" 2."任务栏按钮"选择" ...
- [设计模式] 7 适配器模式 adapter
在 Adapter 模式的结构图中可以看到,类模式的 Adapter 采用继承的方式复用 Adaptee的接口,而在对象模式的 Adapter 中我们则采用组合的方式实现 Adaptee 的复用 类模 ...
- jstl if条件判断字符串代码
<c:if test="${netWorkInfo.networkType eq '快修店'}"> <input type="radio" n ...
- Web Server 和 HTTP 协议
https://toutiao.io/posts/xm2fr/preview 一直在找实习,有点什么东西直接就在evernote里面记了,也没时间来更新到这里.找实习真是个蛋疼的事,一直找的是困难模式 ...
- 1> Strut2 Mapping to MVC
CONTROLLER—FILTERDISPATCHER We’ll start with the controller. It seems to make more sense to start th ...
- C Primer Plus之高级数据表示
抽象数据类型(ADT) 类型是由什么组成?一个类型(type)指定两类信息:一个属性集和一个操作集. 所以您想定义一个新的数据类型.首先,您需要提供存储数据的方式,可能是通过设计一个结构.第二 ...
- [PHP]如何在百度(BAE)和新浪(SAE)的云平台使用PHP连接MySQL并返回结果数据
<?php $dbname = 'VnOTxPFWoxzUBLtrQCCg'; $host = getenv('HTTP_BAE_ENV_ADDR_SQL_IP'); $port = geten ...