以下有1角,2角,5角,1元,2元,5元,10元
问:有多少种方式能刚好组合成100元整?(包括1000个1角也算一种组合)
请以C#方式写出来,并注明注释,可以的话讲讲原理,谢谢。

解决方案 »

  1.   

    动态规划可以,这是以前写的一个程序using System;namespace CSharpTest
    {
        class Program
        {
            static int[] Items;
            static long[,] Matrix;        static void Main(string[] args)
            {
                Items = new int[] { 1000, 500, 200, 100, 50, 20, 10, 5 ,2 ,1};
                int value = 10000;
                Matrix = new long[value + 1, Items.Length];
                Console.WriteLine(GetCount(0, value));
                Console.ReadKey();
            }        static long GetCount(int currentIndex, int remain)
            {
                //如果金额小于0,返回0种
                if (remain < 0)
                    return 0;            //如果金额=0,或算到1元了则正好可以被兑换
                if (remain == 0 || currentIndex == Items.Length - 1)
                    return 1;            if (Matrix[remain, currentIndex] == 0)
                    Matrix[remain, currentIndex] = GetCount(currentIndex + 1, remain) + GetCount(currentIndex, remain - Items[currentIndex]);            return Matrix[remain, currentIndex];
            }
        }
    }
      

  2.   

    请写注释啊
    int value = 10000;
    10000从哪来的