题解

6 条题解

  • 0
    @ 2016-11-10 10:35:56

    正式数据里面m和n最大才取到500

  • 0
    @ 2016-07-17 21:13:12

    只需O(N^2),简单分析
    var n,m,p,i,j,temp:longint;
    coin,gold,walktimes:array[0..1001,0..1001] of longint;
    f,cost:array[0..1001] of longint;
    function return(x:longint):longint;
    begin
    if x=1 then x:=n
    else x:=x-1;
    return:=x;
    end;
    begin
    readln(n,m,p);
    for i:=1 to n do
    for j:=1 to m do read(gold[j,i]);
    for i:=1 to n do read(cost[i]);
    for i:=1 to n do walktimes[0,i]:=p;
    for i:=1 to m do
    begin
    temp:=-maxlongint div 3;
    for j:=1 to n do
    begin
    if walktimes[i-1,return(j)]<p then
    begin
    if coin[i-1,return(j)]+gold[i,j]>f[i-1]-cost[j]+gold[i,j] then
    begin
    walktimes[i,j]:=walktimes[i-1,return(j)]+1;
    coin[i,j]:=coin[i-1,return(j)]+gold[i,j];
    end else
    begin
    walktimes[i,j]:=1;
    coin[i,j]:=f[i-1]-cost[j]+gold[i,j];
    end;
    end
    else
    begin
    coin[i,j]:=f[i-1]-cost[j]+gold[i,j];
    walktimes[i,j]:=1;
    end;
    if temp<coin[i,j] then temp:=coin[i,j];
    end;
    f[i]:=temp;
    end;
    writeln(f[m]);
    end.

  • 0
    @ 2015-08-18 13:34:06

    time limit exceeded
    下面的程序

  • 0
    @ 2014-11-03 22:52:13

    用f(i)表示从还剩下i个单位时间时开始的最大收益,那么它一定是由以前的某个时刻最大收益f(j)(j>i)加上一次行走得到的。因此动态转移方程为:
    f(i)=max{f(j)+sum(k,j-i)-cost(k)}(i<j<=p+i,1<=k<=n)
    其中j表示以前的某个时刻,k表示行走的起点,sum(k,j-i)为从k出发走(j-i)步的金币数,cost(k)为在工厂k买机器人的支出
    在实现时有所不同,我们可以外循环枚举时间,第二重循枚举起点,第三重枚举走的长度。这样在计算sum时可以通过累加得到

    • @ 2014-11-03 22:52:50

      var
      n,m,p,i,j,k,x,sum:longint;
      a:array[0..1000,0..1000]of integer;
      b,f:array[0..1000]of longint;

      function round(x:integer):integer;
      begin
      round:=(x-1)mod n +1;
      end;

      begin
      readln(n,m,p);
      for i:=1 to n do
      begin
      for j:=1 to m do
      read(a[i,j]);
      readln;
      end;
      for i:=1 to n do
      read(b[i]);
      f[0]:=0;
      for i:=1 to m do
      begin
      f[i]:=0;
      for j:=1 to n do
      begin
      sum:=0;
      for k:=1 to p do
      if i>=k then
      begin
      sum:=sum+a[round(j+k-1),m-i+k];
      x:=f[i-k]-b[j]+sum;
      if x>f[i] then f[i]:=x;
      end;
      end;
      end;
      writeln(f[m]);
      end.

    • @ 2016-11-15 20:09:03

      ORZ

  • 0
    @ 2013-10-28 21:36:06

    const oo=maxlongint shr 1;
    var i,j,k,l,m,n,P,Ans,NowM,LastM:Longint;
    S,F,Step:array[0..1000,0..1000] of Longint;
    Cost,Last:array[0..1000] of Longint;
    Begin
    Readln(N,M,P);
    For i:=1 to N do
    For j:=1 to M do Read(S[j,i]);
    For i:=1 to N do Read(Cost[i]);
    For i:=2 to N do Last[i]:=i-1;
    Last[1]:=N;
    Fillchar(Step,sizeof(Step),60);
    For i:=1 to M do
    Begin
    NowM:=-oo;
    For j:=1 to N do
    Begin
    If Step[i-1,Last[j]]<P then
    Begin
    If LastM-Cost[Last[j]]>F[i-1,Last[j]] then
    Begin
    F[i,j]:=LastM-Cost[Last[j]];
    Step[i,j]:=1;
    End Else
    Begin
    F[i,j]:=F[i-1,Last[j]];
    Step[i,j]:=Step[i-1,Last[j]]+1;
    End;
    End Else
    Begin
    F[i,j]:=LastM-Cost[Last[j]];
    Step[i,j]:=1;
    End;
    Inc(F[i,j],S[i,Last[j]]);
    If F[i,j]>NowM then NowM:=F[i,j];
    End;
    LastM:=NowM;
    End;
    Writeln(NowM);
    End.

  • 0
    @ 2013-08-31 16:06:10

    沙发
    const maxn=1000;maxm=1000;
    var
    cost,past:array[0..maxn]of longint;
    coin,f,step:array[0..maxm,0..maxn]of longint;
    n,m,p,pastmax,nowmax,f1,f2,i,j:longint;
    begin
    readln(n,m,p);
    for i:=1 to n do
    for j:=1 to m do read(coin[j,i]);
    for i:=1 to n do read(cost[i]);
    for i:=2 to n do past[i]:=i-1;

    past[1]:=n;
    filldword(step,sizeof(step) shr 2,maxlongint);
    pastmax:=0;
    for i:=1 to m do
    begin
    nowmax:=-maxlongint;
    for j:=1 to n do
    begin
    f1:=pastmax-cost[past[j]]+coin[i,past[j]];
    f2:=f[i-1,past[j]]+coin[i,past[j]];
    if not (step[i-1,past[j]]<p) then begin
    f[i,j]:=f1;
    step[i,j]:=1;
    end
    else begin
    if f1>=f2 then begin
    f[i,j]:=f1;
    step[i,j]:=1;
    end
    else begin
    f[i,j]:=f2;
    step[i,j]:=step[i-1,past[j]]+1;
    end;
    end;
    if f[i,j]>nowmax then nowmax:=f[i,j];
    end;
    pastmax:=nowmax;
    end;
    writeln(nowmax);
    end.

  • 1

信息

ID
1815
难度
5
分类
(无)
标签
递交数
619
已通过
191
通过率
31%
被复制
14
上传者