P1643: [Usaco2007 Oct]Bessie's Secret Pasture 贝茜的秘密草坪

时间:2022-05-10 16:28:45

呵呵呵呵呵,很水的DP,同时能够朴素枚举出来,这数据弱的 是 吃了尸米吧。。

 var n,i,j,k,l,ans:longint;
begin
readln(n);
for i:= to trunc(sqrt(n)) do
for j:= to trunc(sqrt(n)) do
for k:= to trunc(sqrt(n)) do
for l:= to trunc(sqrt(n)) do
if i*i+j*j+k*k+l*l=n then inc(ans);
writeln(ans);
end.

然而这是正确的DP。

 var n,i,j,k:longint;
a:array[..,..] of longint;
begin
readln(n);
for i:= to trunc(sqrt(n)) do
a[,i*i]:=;
for i:= to do
for j:= to n do
for k:= to trunc(sqrt(j)) do
a[i,j]:=a[i,j]+a[i-,j-k*k];
writeln(a[,n]);
end.

(转载请注明出处:http://www.cnblogs.com/Kalenda/)