AlthoughCodeShort, but there are still many places worth learning. The dynamic pattern mainly refers to the state transition equation. Not yet written. For more information, see http://blog.csdn.net/tclh123/article/details/6286833.
At the same time, pay attention to avoid duplication. One is through the largest coin, the For Loop in 50, 25, 10, 5, 1, DP is also from I = A to I = 0, mark the VIS array to avoid repeated computation and save time.
# Include <cstdio> # include <cstring> # include <iostream> # define maxn 7490 using namespace STD; int coin [] = {50, 25, 1 }; int vis [5] [maxn], d [5] [maxn]; int dp (int A, int money) {If (money = 0) return 1; if (vis [a] [money]) return d [a] [money]; vis [a] [money] = 1; int ans = 0; for (INT I = A; I <5; I ++) if (money> = coin [I]) ans + = dp (I, money-coin [I]); d [a] [money] = ans; return ans;} int main () {// freopen ("in.txt", "r", stdin); int Money; while (scanf ("% d", & money )! = EOF) {// memset (VIS, 0, sizeof (VIS); cout <dp (0, money) <Endl ;}return 0 ;}