背景 Background
JSOI2012春季函授A层次考试题
描述 Description
顾神牛考完高考后打算去旅游放松一下自己,可是自己资金不够,不得不向老爸申请拨款,顾爸爸让顾神牛选总和不超过S的若干个不同的正整数,取这些数的约数(不包含本身)之和作为这次的费用。顾神牛希望自己的资金尽量充足,想知道如何使选取的若干个数的约数和最大。
输入格式 Input Format
输入一个正整数S。
输出格式 Output Format
输出最大的约数之和。
样例输入 Sample Input
11
样例输出 Sample Output
9
时间限制 Time Limitation
各个测试点1s
S<=1000
注释 Hint
JSOI2012春季函授A层次考试题
无算法,纯模拟。
var
s,i,j,ans,max,maxn:longint;
a,f:array[1..1001] of longint;
begin
readln(s);
a[1]:=0;
for i:=2 to s do
begin
ans:=1;
for j:=2 to (i div 2) do
if i mod j=0 then
ans:=ans+j;
a[i]:=ans;
end;
f[1]:=0;
f[2]:=1;
if s=1 then
begin
writeln('0');
exit;
end;
maxn:=1;
for i:=3 to s do
begin
max:=a[i];
for j:=1 to i-2 do
if max<f[i-j]+a[j] then
max:=f[i-j]+a[j];
f[i]:=max;
if maxn<max then
maxn:=max;
end;
writeln(maxn);
end.
网站需要实名认证/东营网站推广公司
转载于:https://www.cnblogs.com/shy-/archive/2012/06/27/2566453.html