#1241 : Best Route in a Grid
描述
给定一个N行N列的非负整数方阵,从左上角(1,1)出发,只能向下或向右走,且不能到达值为0的方格,求出一条到达右下角的最佳路径。所谓最佳路径是指途经的数的乘积的末尾连续的0最少。
输入
输入文件的第一行包含一个整数N,其中1≤N≤1000。
接下来的N行每行包含N个非负整数,其中每个数小于等于1,000,000。
数据保证至少存在一条不全为0的路径。
输出
输出文件仅一行,包含一个整数,表示要求的最佳路径上所有数字乘积的末尾连续零的个数。
- 样例输入
-
4
1 3 0 0
0 8 2 25
6 5 0 3
0 15 7 4 - 样例输出
-
2
/* ***********************************************
Author :guanjun
Created Time :2016/3/25 19:56:57
File Name :hiho15a.cpp
************************************************ */
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <iomanip>
#include <list>
#include <deque>
#include <stack>
#define ull unsigned long long
#define ll long long
#define mod 90001
#define INF 0x3f3f3f3f
#define maxn 10010
#define cle(a) memset(a,0,sizeof(a))
const ull inf = 1LL << ;
const double eps=1e-;
using namespace std;
priority_queue<int,vector<int>,greater<int> >pq;
struct Node{
int x,y;
};
struct cmp{
bool operator()(Node a,Node b){
if(a.x==b.x) return a.y> b.y;
return a.x>b.x;
}
}; bool cmp(int a,int b){
return a>b;
}
int b[][],c[][],a;
int dp[][];
int main()
{
#ifndef ONLINE_JUDGE
freopen("in.txt","r",stdin);
#endif
//freopen("out.txt","w",stdout);
int n;
while(cin>>n){
for(int i=;i<=n;i++){
for(int j=;j<=n;j++){
scanf("%d",&a);
if(a==){
b[i][j]=-;
c[i][j]=-;
continue;
}
b[i][j]=c[i][j]=;
while(a%==)b[i][j]++,a/=;
while(a%==)c[i][j]++,a/=;
}
}
memset(dp,INF,sizeof dp);
dp[][]=b[][];
for(int i=;i<=n;i++){
for(int j=;j<=n;j++){
if(b[i][j]==-)continue;
if(i>)dp[i][j]=min(dp[i-][j]+b[i][j],dp[i][j]);
if(j>)dp[i][j]=min(dp[i][j-]+b[i][j],dp[i][j]);
}
}
//cout<<dp[2][2]<<endl;
int ans=dp[n][n];
memset(dp,INF,sizeof dp);
dp[][]=c[][];
for(int i=;i<=n;i++){
for(int j=;j<=n;j++){
if(c[i][j]==-)continue;
if(i>)dp[i][j]=min(dp[i-][j]+c[i][j],dp[i][j]);
if(j>)dp[i][j]=min(dp[i][j-]+c[i][j],dp[i][j]);
}
}
cout<<min(dp[n][n],ans)<<endl;
}
return ;
}
#1241 : Best Route in a Grid的更多相关文章
- hihocoder 1241:Best Route in a Grid
#1241 : Best Route in a Grid 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 给定一个N行N列的非负整数方阵,从左上角(1,1)出发,只能向下 ...
- hihocoder1241 Best Route in a Grid
题目链接:hihocoder 1241 题意: n*n的格阵,每个方格内有一个数字.蚂蚁从左上角走到右下角,数字是零的方格不能走,只能向右向下走.蚂蚁走的路径上全部方格的的乘积为s,要使s低位0的个数 ...
- 广大暑假训练1(poj 2488) A Knight's Journey 解题报告
题目链接:http://vjudge.net/contest/view.action?cid=51369#problem/A (A - Children of the Candy Corn) ht ...
- [4]Telerik Grid 简单使用方法
1.columns <% Html.Telerik().Grid(Model) .Name("Orders") .Columns(columns => { //绑定列名 ...
- hdu 1241 Oil Deposits(DFS求连通块)
HDU 1241 Oil Deposits L -DFS Time Limit:1000MS Memory Limit:10000KB 64bit IO Format:%I64d & ...
- HDU 1241 Oil Deposits(石油储藏)
HDU 1241 Oil Deposits(石油储藏) 00 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Probl ...
- Oracle Grid control 11g及Active DataGuard 11g安装部署
Oracle Grid control 11g及Active DataGuard 11g安装部署(一) 原贴 http://blog.csdn.net/lichangzai/article/detai ...
- (深搜)Oil Deposits -- hdu -- 1241
链接: http://acm.hdu.edu.cn/showproblem.php?pid=1241 Time Limit: 2000/1000 MS (Java/Others) Memory ...
- Oil Deposits HDU - 1241 (dfs)
Oil Deposits HDU - 1241 The GeoSurvComp geologic survey company is responsible for detecting undergr ...
随机推荐
- 【bzoj4568】【Scoi2016】幸运数字 (线性基+树上倍增)
Description A 国共有 n 座城市,这些城市由 n-1 条道路相连,使得任意两座城市可以互达,且路径唯一.每座城市都有一个幸运数字,以纪念碑的形式矗立在这座城市的正中心,作为城市的象征.一 ...
- wamp Apache和mysql服务无法启动的终极解决方法!!!!!!
用了几年的wampserver 突然宣告无法启动,Apache和mysql都崩溃了,在计算机的服务选项里面也是无法启动的,系统报了一个未知错误,重装了N个版本的PHP集成开发环境,都宣告失败! 我想应 ...
- 标准C程序设计七---07
Linux应用 编程深入 语言编程 标准C程序设计七---经典C11程序设计 以下内容为阅读: <标准C程序设计>(第7版) 作者 ...
- LR(1)文法分析器 //c++ 实现
1.先读入终结符,非终结符,和所有产生式. 2.预处理:初始化:getpp()获得每个非终结符在产生式左边时的产生式编号, 记录在 string getp[]中(可以多个). 3.获得所有的符号的fi ...
- 2018 ICPC 沈阳网络赛预赛 Supreme Number(找规律)
[传送门]https://nanti.jisuanke.com/t/31452 [题目大意]:给定一个数字(最大可达10100),现在要求不超过它的最大超级质数.超级质数定义:对于一个数,把它看成数字 ...
- ubuntu下安装翻译软件
原文: http://sixipiaoyang.blog.163.com/blog/static/6232358820144146386437/ Ubuntu下常用的翻译软件有StarDict,Gol ...
- Atcoder Grand Contest 023
A 略 B 略 C(计数) 题意: 有n个白球排成一行,故有n-1个空隙,我可以给一个空隙对应的两个白球都涂黑.n-1个空隙的一个排列就对应着一个涂黑顺序,定义这个涂黑顺序的价值是“将所有n个球都涂黑 ...
- NRapid前言
开发工具 Visual Studio 2017 数据库 SQL Server 2012 相关技术 Asp.net MVC
- ceph工作原理和安装
一.概述 Ceph是一个分布式存储系统,诞生于2004年,最早致力于开发下一代高性能分布式文件系统的项目.随着云计算的发展,ceph乘上了OpenStack的春风,进而成为了开源社区受关注较高的项目之 ...
- MBProgressHUD 显示方向异常
一直在iphone上使用MBProgressHUD做提示信息视图.一直都没有什么问题,但用在ipad上使用时.却有时会出现显示方向不正常.如ipad屏幕是横的,但当MBProgressHUD出现时却依 ...