T3:
题解:
先预处理出每个数的因数和,然后在进行DP
转移方程:f[i,j]表示到数字i,总和为j的最大因数和,f[i,j]=max(f[i-1,j-i]+a[i],f[i-1,j]);
参考程序:
var n,i,j,t:longint;
a:array[1..1000]of longint;
f:array[0..1000,0..1000]of 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:=2 to n do
for j:=1 to i-1 do
if i mod j=0 then a[i]:=a[i]+j;
for i:=1 to n do
for j:=0 to n do
if j-i>=0 then f[i,j]:=max(f[i-1,j-i]+a[i],f[i-1,j]) else
f[i,j]:=f[i-1,j];
writeln(f[n,n]);
close(input);close(output);
end.