记录编号 |
673 |
评测结果 |
AWWWWEEEEE |
题目名称 |
[NOI 1999]生日蛋糕 |
最终得分 |
10 |
用户昵称 |
Oo湼鞶oO |
是否通过 |
未通过 |
代码语言 |
Pascal |
运行时间 |
1.878 s |
提交时间 |
2008-07-20 16:15:35 |
内存使用 |
0.00 MiB |
显示代码纯文本
program cake;
var n,m,r,h,mxmin:longint;
txt:text;
procedure dfs(ceng,lr,lh,s,usen:longint);
var r,h,e,s1:longint;
begin
if (ceng=0)and(s<mxmin) then
begin
if usen=0 then mxmin:=s;
end else
for r:=1 to lr-1 do
for h:=1 to usen div sqr(r) do
begin
usen:=usen-sqr(r)*h;
if (usen<>0)or((ceng=1)and(usen=0)) then
dfs(ceng-1,r,h,s+2*r*h,usen);
end;
end;
begin
assign(txt,'cake.in');
reset(txt);
readln(txt,n,m);
close(txt);
mxmin:=maxlongint;
if (m<=n)and(m<>0) then
for r:=1 to trunc(sqrt(n div m)) do
for h:=1 to n div sqr(r) do
dfs(m-1,r,h,2*r*h+sqr(r),n-sqr(r)*h);
assign(txt,'cake.out');
rewrite(txt);
if mxmin=maxlongint then mxmin:=0;
writeln(txt,mxmin);
close(txt);
end.