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

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

 1 var n,i,j,k,l,ans:longint;
 2 begin
 3   readln(n);
 4   for i:=0 to trunc(sqrt(n)) do
 5     for j:=0 to trunc(sqrt(n)) do
 6       for k:=0 to trunc(sqrt(n)) do
 7         for l:=0 to trunc(sqrt(n)) do
 8           if i*i+j*j+k*k+l*l=n then inc(ans);
 9   writeln(ans);
10 end.
View Code

然而这是正确的DP。

 1 var n,i,j,k:longint;
 2 a:array[0..4,0..10001] of longint;
 3 begin
 4   readln(n);
 5   for i:=0 to trunc(sqrt(n)) do
 6     a[1,i*i]:=1;
 7   for i:=2 to 4 do
 8     for j:=0 to n do
 9       for k:=0 to trunc(sqrt(j)) do
10         a[i,j]:=a[i,j]+a[i-1,j-k*k];
11   writeln(a[4,n]);
12 end.
View Code

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

posted @ 2015-09-22 19:13  LovelyMonster丶  阅读(188)  评论(0编辑  收藏  举报