Total number of solutions for hdu 1284 coin exchange problem full backpack ~

Source: Internet
Author: User

Total number of solutions for hdu 1284 coin exchange problem full backpack ~
Coin Exchange ProblemsTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission (s): 6296 Accepted Submission (s): 3640


Problem Description has only one cent, two cent, and three cent coins in a country. There are many exchange methods to convert money N into coins. Compile a program to calculate the total number of exchange methods.
Each Input row has only one positive integer N, and N is less than 32768.
Output corresponds to the number of exchange methods for each input.
Sample Input

293412553

Sample Output
71883113137761 state transition equation: dp [I] [j] = dp [I-1] [j] + dp [1] [j-(1 ~ 3)] (d [0] [0] = 1); Code:
#include 
  
   #include 
   
    #define MAX 35000int dp[MAX] ;int main(){int n;while(scanf("%d",&n) != EOF){memset(dp,0,sizeof(int)*(n+10)) ;dp[0] = 1 ;for(int i = 1 ; i <= 3 ; ++i){for(int j = i ; j <= n ; ++j)dp[j] = dp[j]+dp[j-i] ;}printf("%d\n",dp[n]) ;}return 0 ;}
   
  

A god Code (not written by me) is provided to you ):
# Include
  
   
Int main () {int n, sum, I; while (scanf ("% d", & n )! = EOF) {int t = n/3 + 1; // number of 3 points sum = 0; for (I = 0; I
   
    
Because the number of coins in this question is only one, two, three, so t = n/3, and then traverse the I from 0 to t, representing the number of three points of the nominal value, then, subtract the value represented by the trigger coin from the total value, and divide it by 2. The resulting number is the total number of coins exchanged for 2 points after each trigger. The final addition of all points is the solution.

The following code is a bunker.

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.