Skip to content

Instantly share code, notes, and snippets.

@carlcarl
Created April 12, 2012 19:16
Show Gist options
  • Save carlcarl/2370264 to your computer and use it in GitHub Desktop.
Save carlcarl/2370264 to your computer and use it in GitHub Desktop.
硬幣組合
#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