当前位置: 代码迷 >> 综合 >> 【NOIP2011模拟9.1】方格取数 (Standard IO)
  详细解决方案

【NOIP2011模拟9.1】方格取数 (Standard IO)

热度:13   发布时间:2023-10-09 12:23:20.0

Description

给定一个N*M的矩阵,记录左上角为(1,1),右下角为(N,M),现在从(1,1)开始取数,每次只能向下或向右移动一个单位,最终到达(N,M),我们把路径上所有的数相乘,记为C。使C的结果最大已经不能满足我们了,现在我们想让C末尾的零最少。
  Ps.11000末尾有3个零,100000100末尾有2个零。


题解:

我们只要把输入的数分解成25,把25的数量记录下来,两幅图中找一条最小路径之后就OK了。


代码:
vari,j,n,m,k,l:longint;a,b,c:array[0..1000,0..1000] of int64;
function min(x,y:longint):longint;
beginif x>y then min:=yelse min:=x;
end;
procedure main;
beginreadln(n,m);for i:=1 to n dofor j:=1 to m doread(a[i,j]);for i:=1 to n dofor j:=1 to m dobegink:=a[i,j];l:=0;while k mod 2=0 dobegink:=k div 2;inc(l);end;b[i,j]:=l;k:=a[i,j];l:=0;while k mod 5=0 dobegink:=k div 5;inc(l);end;c[i,j]:=l;end;
end;
beginmain;for i:=1 to n dobeginb[i,0]:=maxlongint;c[i,0]:=maxlongint;end;for i:=1 to m dobeginb[0,i]:=maxlongint;c[0,i]:=maxlongint;end;for i:=1 to n dofor j:=1 to m doif (i<>1)or(j<>1) thenb[i,j]:=b[i,j]+min(b[i-1,j],b[i,j-1]);for i:=1 to n dofor j:=1 to m doif (i<>1)or(j<>1) thenc[i,j]:=c[i,j]+min(c[i-1,j],c[i,j-1]);writeln(min(c[n,m],b[n,m]))
end.

  相关解决方案