Test instructions: Give 1,5,10,25,50 five kinds of coins, and then give N, ask how many different schemes can gather n
Write your own writing when the program number is always less (one-dimensional)
Later found that the search, to use two-dimensional to write
http://blog.csdn.net/keshuai19940722/article/details/11025971
This article says there will be a repetition of the face value, not quite understand
There is a preprocessing problem, after looking at the puzzle to write their own, it is customary to handle the DP array to write to the while loop inside, has been tle
And then I saw this.
Http://www.cnblogs.com/scau20110726/archive/2012/12/25/2832968.html
Because the topic does not say how many sets of data, if the processing of the DP array in the while loop, if you give a 10w group of data, it will definitely time out (equivalent to each time, to deal with the DP Array)
So just put the pretreatment on the outside.
1#include <iostream>2#include <cstdio>3#include <cstring>4#include <cmath>5#include <stack>6#include <vector>7#include <map>8#include <Set>9#include <queue>Ten#include <algorithm> One #definemod=1e9+7; A using namespacestd; - -typedefLong LongLL; the Const intINF =0x7fffffff; - Const intmaxn=8005; -LL dp[maxn][ the]; - intcoin[5]={1,5,Ten, -, -}; + -LL DFS (intSinti) { + if(dp[s][i]!=-1)returnDp[s][i]; A atdp[s][i]=0; - for(intj=i;j<5&&s>=coin[j];j++) -Dp[s][i]+=dfs (S-coin[j],j); - - returnDp[s][i]; - } in - intMain () { to intN; +memset (dp,-1,sizeof(DP)); - for(intI=0;i<5; i++) dp[0][i]=1; the while(SCANF ("%d", &n)! =EOF) { * $printf"%lld\n", DFS (N,0));Panax Notoginseng } - return 0; the}
View Code
UVa 674 Coin Change "Memory Search"