From 94ffd5d4820bc2d63411a1f8e34c98120282936e Mon Sep 17 00:00:00 2001 From: KiritoTRw <3021577574@qq.com> Date: Sat, 7 May 2016 19:55:59 +0800 Subject: [PATCH] Create 1398_cnblogs.cpp From http://www.cnblogs.com/qiufeihai/archive/2012/09/11/2680840.html --- HDOJ/1398_cnblogs.cpp | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 HDOJ/1398_cnblogs.cpp diff --git a/HDOJ/1398_cnblogs.cpp b/HDOJ/1398_cnblogs.cpp new file mode 100644 index 0000000..3c489d4 --- /dev/null +++ b/HDOJ/1398_cnblogs.cpp @@ -0,0 +1,32 @@ +#include +#include +#include +#include +using namespace std; + +const int M = 300 + 10; + +int dp[M]; + +int main() +{ + int n; + while (~scanf("%d", &n), n) + { + + memset(dp, 0, sizeof(dp)); + dp[0] = 1; + + int max = (int)sqrt(n * 1.0); + for (int i = 1; i <= max; i++) + { + for (int j = i * i; j <= n; j++) + { + dp[j] += dp[j - i * i]; + } + } + + printf("%d\n", dp[n]); + } + return 0; +}