不错的基础dp
首先建立两个三维数组,一个记录map[i][j][k]=sum为坐标(i,j,k)的点权值为sum,
另一个数组初值为0,dp转移方程:f[i][j][k]:=max(f[i-1][j][k],f[i][j-1][k],f[i][j][k-1]);
代码
var f,map:array[0..101,0..101,0..101] of longint; i,j,k,l,m,n,x,y,z,sum:longint; function max(a,b,c:longint):longint; begin max:=-maxlongint; if a>max then max:=a; if b>max then max:=b; if c>max then max:=c; end; begin readln(x,y,z); readln(m); for i:=1 to m do readln(j,k,l,map[j][k][l]); for i:=1 to x do for j:=1 to y do for k:=1 to z do f[i][j][k]:=max(f[i-1][j][k],f[i][j-1][k],f[i][j][k-1])+map[i][j][k]; readln(sum); if f[x][y][z]>=sum then writeln(f[x][y][z]) else writeln(‘BigBang!‘); end.
喜欢就收藏一下,vic私人qq:1064864324,加我一起讨论问题,一起进步^-^
时间: 2024-10-14 04:59:58