Created
April 12, 2012 19:16
-
-
Save carlcarl/2370264 to your computer and use it in GitHub Desktop.
硬幣組合
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
int coin(const int coin, const int value) | |
{ | |
int i, j; | |
int array[value + 1]; | |
for(j = 1; j < value + 1; j++) | |
{ | |
array[j] = 0; | |
} | |
array[0] = 1; | |
for(i = 1; i <= coin; i++) | |
{ | |
for(j = i; j < value + 1; j++) | |
{ | |
array[j] = array[j] + array[j - i]; | |
} | |
} | |
return array[value]; | |
} | |
int main() | |
{ | |
// printf("%d\n", coin(30, 27)); | |
printf("%d\n", coin(30, 77)); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment