C程序找零钱

c程序找零钱

在这个问题中,我们给定一个值n,我们想要找零n卢比,并且我们有n个硬币,每个硬币的面值从1到m不等。我们需要返回能够组成这个总和的方式的总数。

例子

Input : N = 6 ; coins = {1,2,4}.Output : 6Explanation : The total combination that make the sum of 6is :{1,1,1,1,1,1} ; {1,1,1,1,2}; {1,1,2,2}; {1,1,4}; {2,2,2} ; {2,4}.

登录后复制

Example

的中文翻译为:

示例

#include int coins( int S[], int m, int n ) {   int i, j, x, y;   int table[n+1][m];   for (i=0; i= 0)? table[i - S[j]][j]: 0;         y = (j >= 1)? table[i][j-1]: 0;         table[i][j] = x + y;      }   }   return table[n][m-1];}int main() {   int arr[] = {1, 2, 3};   int m = sizeof(arr)/sizeof(arr[0]);   int n = 4;   printf("The total number of combinations of coins that sum up to %d",n);   printf(" is %d ", coins(arr, m, n));   return 0;}

登录后复制

输出

The total number of combinations of coins that sum up to 4 is 4

登录后复制

以上就是C程序找零钱的详细内容,更多请关注【创想鸟】其它相关文章!

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至253000106@qq.com举报,一经查实,本站将立刻删除。

发布者:PHP中文网,转转请注明出处:https://www.chuangxiangniao.com/p/2585405.html

(0)
上一篇 2025年3月6日 15:02:12
下一篇 2025年2月28日 10:41:47

AD推荐 黄金广告位招租... 更多推荐

相关推荐

发表回复

登录后才能评论