2016-05-20 Problem Solving►UVa UVa 11407 - Squares Contents 1. Problem2. Solution3. Code Problem題目網址中文網址 注意同樣數字,重複出現仍算不同項。 Solution建完表後做 DP,像背包問題。 CodeUVa 11407UVa 11407 - Squares123456789101112131415161718192021222324252627282930#include<cstdio>#define MIN(a,b) ((a)<(b)?(a):(b))#define N 101#define M 10001int main(){ int dp[M] = {}; int square[N] = {}, i, j; for (j = 1; j < M; ++j) dp[j] = 10001; for (i = 1; i < N; ++i) square[i] = i*i; for (i = 1; i < N; ++i) for (j = square[i]; j < M; ++j) dp[j] = MIN(dp[j - square[i]] + 1, dp[j]); int n,Case; scanf("%d", &Case); while (Case--) { scanf("%d", &n); printf("%d\n", dp[n]); } return 0;} Newer UVa 11475 - Extend to Palindrome Older UVa 10557 - XYZZY