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.