[HRBUST1472] Coin (DP, Count)

Source: Internet
Author: User

Title Link: http://acm-software.hrbust.edu.cn/problem.php?id=1472

Test instructions: Give n a coin, the face value is random. Ask the number of categories that happen to be in M-dollar (remove duplicates).

DP (I,J,K) denotes i-coins, J-elements, and the maximum number of classes of K.

At first, the mentally retarded memory Dfs burst T is more than just a recursive or a T.

The result is to consider adding some pruning to the memory Dfs first, or T.

The recursion to do some processing, found that because the current maximum enumeration, the largest L if it is j+2, even if it is only one, is greater than j+1. To see here, is forward to recursion, that is to say, the minimum par value of the topic is 1, in the recursive time just maintain in J is not satisfied, need to j+1.

1#include <bits/stdc++.h>2 using namespacestd;3typedefLong LongLL;4 ConstLL mod =2000000007;5 Const intMAXN = -;6 LL DP[MAXN][MAXN][MAXN];7 intN, M;8 9LL DFS (intNintMintpre) {Ten     if(Dp[n][m][pre]! =-1)returnDp[n][m][pre]; One     //if (pre > M) return dp[n][m][pre] = 0; A     if(n = =0) { -         if(M = =0)returnDp[n][m][pre] =1; -         returnDp[n][m][pre] =0; the     } -Dp[n][m][pre] =0; -      for(inti = Pre; I <= m; i++) { -         if(M-i <0) Break; +Dp[n][m][pre] = (Dp[n][m][pre] + DFS (n-1, M-i, i))%MoD; -     } +     returnDp[n][m][pre]; A } at  - intMain () { -     //freopen ("in", "R", stdin); -     intT; -scanf"%d", &T); -Memset (DP,0,sizeof(DP)); indp[1][1][1] =1; -      for(inti =1; I <= $; i++) { to          for(intj =1; J <= $; J + +) { +              for(intK =1; K <= $; k++) { -                 if(Dp[i][j][k] = =0)Continue; the                  for(intL = k; J + L <= $; l++) { *                     if(L > J +1) Break; $dp[i+1][j+l][l] = (dp[i+1][J+L][L] + dp[i][j][k])%MoD;Panax Notoginseng                 } -             } the         } +     } A      while(t--) { thescanf"%d%d",&n,&m); +LL ret =0; -          for(inti =1; I <= m; i++) { $RET = (ret + dp[n][m][i])%MoD; $         } -printf"%lld\n", ret); -     } the     return 0; -}

[HRBUST1472] Coin (DP, Count)

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.