Title Link: http://poj.org/problem?id=1664
DP[I][J] Indicates the number of schemes of J apples for I disks, dp[i][j] can be recursive by dp[i-1][j] and Dp[i][j-i].
When the number of plates is greater than or equal to the number of apples:
DP[I-1][J]: I-1 a tray of J apples, indicating that I have at least one tray on the plate is empty
Dp[i][j-i]: I have a plate of apples, indicating that there are j-i apples are casually placed
Otherwise:
DP[I][J] = Dp[i-1][j]
Then the plan for a plate without apples is 1, i.e. dp[i][0] = 1
1#include <iostream>2#include <cstdio>3#include <cstring>4#include <algorithm>5 using namespacestd;6 intdp[ the][ the];7 intMain ()8 {9 for(inti =1; I <=Ten; ++i)Tendp[i][0] =1; One for(inti =1; I <=Ten; ++i) { A for(intj =1; J <=Ten; ++j) { - if(J-i >=0) -DP[I][J] = dp[i-1][J] + dp[i][j-i]; the Else -DP[I][J] = dp[i-1][j]; - } - } + intt, N, M; -CIN >>T; + while(t--) { ACIN >> M >>N; atcout << Dp[n][m] <<Endl; - } -}
POJ 1664 putting apples (recursion)