#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
- 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 ...
随机推荐
- 【霍夫曼树】poj 1339 poker card game (数组排序+辅助队列的方法,预处理O(nlogn),构造霍夫曼树O(n))
poj.org/problem?id=1339 #include<iostream> #include<cstdio> #include<string> #incl ...
- bzoj3609 [Heoi2014]人人尽说江南好 博弈
[Heoi2014]人人尽说江南好 Time Limit: 10 Sec Memory Limit: 256 MBSubmit: 581 Solved: 420[Submit][Status][D ...
- docker管理工具推荐(linux和windows)
1.windows. 下载dokcer toolbox即可 2.linux 推荐rancher.安装链接参考:http://www.kaimingwan.com/post/rong-qi-yu-ron ...
- uva 1426 离散平方根
1426 - Discrete Square Roots Time limit: 3.000 seconds A square root of a number x <tex2html_verb ...
- 洛谷 [P3150] pb的游戏
博弈论基础 本题可以视作P2148 E&D 的前置技能 本题直接判断奇偶性来求解, 证明就是2148 的证明 不贴代码
- 图表控件Anychart常见问题
AnyChart控件是一款当前流行的数据可视化解决方案,使客户可以创建交互地.生动的图表.实时仪表和地图.同时支持Flash和HTML5显示,控件提供极好的视觉外观和配色方案能够使客户根据不同的需求设 ...
- PXC小结
PXC使用到的端口号 3306 数据库对外服务的端口号(视具体情况而定) 4444 请求SST SST: 指数据一个镜象传输 xtrabackup , rsync ,mysqldump 4567 : ...
- 多线程之 Volatile 变量 详解
Java 理论与实践: 正确使用 Volatile 变量 原文:http://www.ibm.com/developerworks/cn/java/j-jtp06197.html 总结: volati ...
- Centos7安装遇到的问题及详解
1.虚拟机中选择的是NAT模式,我的笔记本电脑是拨号上网,用桥接模式,找不到网卡,在windows的dos界面用ipconfig查看的结果 PPP适配器 宽带连接:IPv4 地址 . . . . . ...
- RED HAT 7 性能监控工具
https://access.redhat.com/documentation/zh-CN/Red_Hat_Enterprise_Linux/7/html/Performance_Tuning_Gui ...