时间限制: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. leetcode 94 中序遍历模板

    /**递归的写法 * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * Tre ...

  2. Vmware error:无法获得 VMCI 驱动程序的版本: 句柄无效。

    error:无法获得 VMCI 驱动程序的版本: 句柄无效.驱动程序“vmci.sys”的版本不正确.请尝试重新安装 VMware Workstation.开启模块 DevicePowerOn 的操作 ...

  3. angular中关于自定义指令——repeat渲染完成后执行动作

    业务中有时需要在异步获取数据并用ng-repeat遍历渲染完页面后执行某个操作,angular本身并没有提供监听ng-repeat渲染完成的指令,所以需要自己动手写.有经验的同学都应该知道,在ng-r ...

  4. shell的while/for脚本的简单入门

    shell的while/for脚本的简单入门 while [condition] dodone关键字break跳出循环,continue跳过循环的余下部分. for var in ...;do...d ...

  5. 小程序-列表块/类式ul-li格式(1)

    摘要 目前列表能布局出来,但是目前我个人还没解决的问题是:如果每个列表块都有详情页怎么解决呢? 1:我的效果图 2.正常的每个都能点击的html 注:上面的代码确实能够实现我的每个[menu2_vie ...

  6. javafx中多场景的切换

    0.前言 前段时间在做javafx的应用程序,遇到一些坑.以本文记录之.(如有更好的解决办法欢迎评论,本人小白,轻喷) 1.问题 按照官方的中文文档,成功的运行了单一界面的表单登录.于是想自己试试多界 ...

  7. java实现简单的算法

    排序大的分类可以分为两种:内排序和外排序.在排序过程中,全部记录存放在内存,则称为内排序,如果排序过程中需要使用外存,则称为外排序.下面讲的排序都是属于内排序. 内排序有可以分为以下几类: (1).插 ...

  8. 解决树莓派8G的SD卡只能识别3.3G,SD卡扩容

    8GB microSD在Windows下使用Win32 Disk Imager下载映像后,在RPi中只能识别出3.3GB.而本身还有很多容量没有释放出来. 使用sudo raspi-config工具可 ...

  9. python type

    基于2.7 版本 type 是内置函数,有两种用法 class type(object) With one argument, return the type of an object. The re ...

  10. .net core mvc启动顺序以及主要部件1

    原文:.net core mvc启动顺序以及主要部件1 首先我是新人一个写这些东西也是为了增加记忆,有不对的地方请多多指教. 说回正题,打开Program.cs文件,看到在有个CrateWebHost ...