Chinaunix首页 | 论坛 | 博客
  • 博客访问: 214287
  • 博文数量: 68
  • 博客积分: 3120
  • 博客等级: 中校
  • 技术积分: 715
  • 用 户 组: 普通用户
  • 注册时间: 2008-03-08 09:53
文章分类
文章存档

2012年(29)

2011年(3)

2010年(18)

2009年(18)

我的朋友

分类: C/C++

2012-02-04 12:06:22

问题:

In England the currency is made up of pound, £, and pence, p, and there are eight coins in general circulation:

1p, 2p, 5p, 10p, 20p, 50p, £1 (100p) and £2 (200p).

It is possible to make £2 in the following way:

1×£1 + 1×50p + 2×20p + 1×5p + 1×2p + 3×1p

How many different ways can £2 be made using any number of coins?

答案:73682

#include

int m[8]={1,2,5,10,20,50,100,200};

int methods(int n, int *m, int len)
{
    if (len == 1)
        return 1;
    else {
        int k = n / m[len-1];
        int sum=0;
        int i = 0;

        for (i=0; i<=k; i++)
            sum += methods (n-m[len-1]*i, m, len-1);
        return sum;
    }
}

int main(void)
{
    int count=0;
    count = methods (200, m, 8);
    printf("%d\n", count);

    return 0;

}


阅读(981) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~