1. 程式人生 > >OIBH杯第三次模擬賽(普及組)Problem 3 : maxsum 最大約數和

OIBH杯第三次模擬賽(普及組)Problem 3 : maxsum 最大約數和

題意:

給一個s,用和不超過s 的數使得他們的因數和最大,不包括本身。

思路:

水dp
f[i]:=f[k]+f[n-k];

程式:

const
 maxn=1000;
var
 f:array [0..maxn] of longint;
 i,j,n,m,x,k:longint;

function  max(x,y:longint):longint;
begin
 if x>y then exit(x)
        else exit(y);
end;

begin
 assign(input,'maxsum.in'); reset(input);
 assign(output,'maxsum.out'
); rewrite(output); readln(n); for i:=1 to n do begin x:=0; for j:=1 to i-1 do if i mod j=0 then x:=x+j; f[i]:=x; end; for i:=1 to n do for k:=0 to i-1 do f[i]:=max(f[i],f[i-k]+f[k]); writeln(f[n]); close(input); close(output); end.