1643: [Usaco2007 Oct]bessie ' s Secret pasture Bessie's Secret lawn time limit:5 Sec Memory limit:64 MB
submit:295 solved:250
[Submit] [Status] [Discuss] Description
Farmer John has made a number of square turf from his ranch, the side length of the turf is always an integer (sometimes the farmer John cuts the turf of the knife is not appropriate, even cut out the side of the 0 square turf), he has put the turf in a cow Bessie already know the place. Bessie had always wanted to put the delicious turf in her secret manor, and she decided to take exactly 4 pieces out of the turf and move them into her secret manor, and then split them into 1x1 pieces, forming a portion of an area of N (1<=n<=10,000) units. Bessie was interested in the number of methods for selecting such four pieces of turf, and if she got a 4 unit area, she could have 5 different ways to choose 4 Turf: (1,1,1,1), (2,0,0,0), (0,2,0,0), (0,0,0,2). The order is valid: ( 4,3,2,1) and (1,2,3,4) are different methods.
Input
First line: A separate integer n.
Output
A separate line contains an integer representing the number of options that Bessie chose for four turf.
Sample Input4Sample Output5
HINT Source
Silver
Abuse problem, no difficulty happy ing ...
----------------------------------------------------------------------------
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <deque>
using namespace Std;
int dp[10005][5];
int main () {
int n;
scanf ("%d", &n);
Dp[0][0]=1;
for (int i=1;i<=n;i++)
for (int j=1;j<=4;j++)
for (int k=0;k*k<=i;k++) {
DP[I][J]+=DP[I-K*K][J-1];
}
printf ("%d\n", dp[n][4]+dp[n][1]+dp[n][2]+dp[n][3]);
return 0;
}
---------------------------------------------------------------------------
bzoj1643: Bessie's Secret lawn