codevs1028

来源:互联网 发布:ai矢量制图软件 编辑:程序博客网 时间:2024/04/29 15:50

题目地址:http://codevs.cn/problem/1028/

分析:

DP。

 if (ff[i-1][k]+a[i][j]>ff[i][j]) then ff[i][j]:=ff[i-1][k]+a[i][j];  

代码:

var
  a,ff:array[0..1000,0..1000]of integer;
  f,v,i,j,k,max:longint;

begin
  assign(input,'flower.inp');
  reset(input);
  read(f,v);
  for i:=1 to f do
    for j:=1 to v do
      read(a[i,j]);
  close(input);
  assign(output,'flower.out');
  rewrite(output);
  fillchar(ff,sizeof(ff),0);
  for i:=0 to v do
    ff[0,i]:=0;
  for i:=1 to f do
    for j:=i to v do
      for k:=0 to j-1 do
        if (ff[i-1][k]+a[i][j]>ff[i][j]) then
          ff[i][j]:=ff[i-1][k]+a[i][j];
  max:=0;
  for i:=1 to v do
    if max<ff[f][i] then
      max:=ff[f][i];
  writeln(max);

  close(output);
end.


0 0