UVa 674 Coin Change "Memory Search"

Source: Internet
Author: User

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"

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.