Noip2004P2 花生采摘

18 篇文章 0 订阅
9 篇文章 0 订阅

题目:

 花生采摘

来源:

 Noip2004P2

题目大意:

 M*N的矩阵中每个点有值,可进行k次操作,求依次去最大值最多能去多少。

 每次操作为以下之一

 1) 从路边跳到最靠近路边(即第一行)的某棵花生植株;
 2) 从一棵植株跳到前后左右与之相邻的另一棵植株;
 3) 采摘一棵植株下的花生;
 4) 从最靠近路边(即第一行)的某棵花生植株跳回路边。

数据范围:

 1 <= M, N <= 20、0 <= K <= 1000

样例:

 6 7 21

 0 0 0 0 0 0 0

 0 0 0 0 13 0 0

 0 0 0 0 0 0 7

 0 15 0 0 0 0 0

 0 0 0 9 0 0 0

 0 0 0 0 0 0 0

37

做题思路:

 依照题意每次取最大知道剩下的操作数只够回到路边,记得啊这不是动规,还有采摘  也算操作。

知识点:

 模拟、贪心

type
 act=record
 x,y,d:longint;
 end;
var
 a:array[0..500]of act;
 n,m,i,j,ans,k,tot,x,y:longint;
//==================================================
procedure qsort(l,r:longint);
var
 i,j,k:longint;
 t:act;
begin
 i:=l;j:=r;
 k:=a[(l+r)shr 1].d;
 repeat
  whilea[i].d>k do inc(i);
  whilea[j].d<k do dec(j);
  ifi<=j then
  begin
   t:=a[i];a[i]:=a[j];a[j]:=t;
   inc(i);dec(j);
   end;
 untili>j;
 ifi<r then qsort(i,r);
 ifj>l then qsort(l,j);
end;
//================================================
begin
 readln(m,n,k);
 fori:=1 to m do
  begin
   forj:=1 to n do
   begin
    inc(tot);
    read(a[tot].d);
    a[tot].x:=i;a[tot].y:=j;
   end;
  readln;
  end;
 qsort(1,tot);
 i:=1;
 y:=a[1].y;x:=0;
 while(k>=0)and(i<=tot) do
  begin
   if(k-(abs(a[i].x-x)+abs(a[i].y-y))-a[i].x-1)>=0 then{<前往目标值距离和回到路边的距离和采摘操作总和是否在操作数内>}
   begin
    k:=k-(abs(a[i].x-x)+abs(a[i].y-y))-1;{<走过去并采摘>}
    x:=a[i].x;y:=a[i].y;
    inc(ans,a[i].d);
    end
   elsek:=0;{<不满足条件直接回路边>}
  inc(i);
  end;
 writeln(ans);
end.
题目来源: http://yuanti.tyvj.cn:8080/Problem_Show.asp?id=1043

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值