时间限制:10000ms
单点时限:1000ms
内存限制:256MB

描述

给定一个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的更多相关文章

  1. hihocoder 1241:Best Route in a Grid

    #1241 : Best Route in a Grid 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 给定一个N行N列的非负整数方阵,从左上角(1,1)出发,只能向下 ...

  2. hihocoder1241 Best Route in a Grid

    题目链接:hihocoder 1241 题意: n*n的格阵,每个方格内有一个数字.蚂蚁从左上角走到右下角,数字是零的方格不能走,只能向右向下走.蚂蚁走的路径上全部方格的的乘积为s,要使s低位0的个数 ...

  3. 广大暑假训练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. [4]Telerik Grid 简单使用方法

    1.columns <% Html.Telerik().Grid(Model) .Name("Orders") .Columns(columns => { //绑定列名 ...

  5. hdu 1241 Oil Deposits(DFS求连通块)

    HDU 1241  Oil Deposits L -DFS Time Limit:1000MS     Memory Limit:10000KB     64bit IO Format:%I64d & ...

  6. HDU 1241 Oil Deposits(石油储藏)

    HDU 1241 Oil Deposits(石油储藏) 00 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)   Probl ...

  7. Oracle Grid control 11g及Active DataGuard 11g安装部署

    Oracle Grid control 11g及Active DataGuard 11g安装部署(一) 原贴 http://blog.csdn.net/lichangzai/article/detai ...

  8. (深搜)Oil Deposits -- hdu -- 1241

    链接: http://acm.hdu.edu.cn/showproblem.php?pid=1241 Time Limit: 2000/1000 MS (Java/Others)    Memory ...

  9. Oil Deposits HDU - 1241 (dfs)

    Oil Deposits HDU - 1241 The GeoSurvComp geologic survey company is responsible for detecting undergr ...

随机推荐

  1. oracle 连接数据库以及查看当前用户、当前数据库实例

    sql>show user;查看当前用户 sql>show parameter instance_name;查看当前数据库实例 例如: sqlplus登录:用sys用户登录(密码是1234 ...

  2. Codeforces 848B Rooter's Song(分类+模拟)

    题目链接 Rooter's Song 题意  有n个舞者站在x轴上或y轴上,每个人有不同的出发时间.x轴上的舞者垂直x轴正方向移动,y轴上的舞者垂直y轴正方向移动. 当x轴的舞者和y轴的舞者相遇时,他 ...

  3. P2007 魔方

    洛谷——P2007 魔方 题目背景 常神牛从来没接触过魔方,所以他要借助计算机来玩.即使是这样,他还是很菜. 题目描述 常神牛家的魔方都是3*3*3的三阶魔方,大家都见过. (更正:3 4以图为准.) ...

  4. 《Java虚拟机原理图解》 1.2.2、Class文件中的常量池详解(上)

    我的上一篇文章<Java虚拟机原理图解> 1.class文件基本组织结构中已经提到了class的文件结构,在class文件中的魔数.副版本号.主版本之后,紧接着就是常量池的数据区域了,如下 ...

  5. 【chrome错误】Cross origin requests are only supported for protocol schemes: http, data,chrome-extension, https, chrome-extension-reso

    使用ajax请求本地文件,chrome会报跨域错误. XMLHttpRequest cannot loadfile:///C:/Users/Li/Desktop/images/alist.json.C ...

  6. Maven自动部署(SCM-SVN/Git)(maven-scm-plugin/maven-release-plugin插件的使用)

    以下内容引用自https://ayayui.gitbooks.io/tutorialspoint-maven/content/book/maven_deployment_automation.html ...

  7. react 起手式

    http://blog.csdn.net/zhouzhiande/article/details/52349344 http://blog.csdn.net/zhouzhiande/article/d ...

  8. org.apache.catalina.connector.ClientAbortException: java.io.IOException: APR error:-32

    org.apache.catalina.connector.ClientAbortException: java.io.IOException: APR error:-32 Most likely, ...

  9. 杭电1863 畅通project

    畅通project Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total ...

  10. IntelliJ IDEA cannot resolved 处理

    IntelliJ IDEA cannot resolved 处理 学习了:https://stackoverflow.com/questions/21577573/intellij-idea-can- ...