用1元,2元,5元,10元,20元和50元的纸币组成100元,共有多少种情况

来源:互联网 发布:班级排座位软件 编辑:程序博客网 时间:2024/04/28 00:05

  static void Main(string[] args)
        {
            int count = 0;
            //1元组成的情况,最多有100种
            for (int a = 0; a <= 100; a++)
            {
                //2元的情况,最多有50种可能
                for (int b = 0; b <= 50; b++)
                {
                    for (int c = 0; c <= 20; c++)
                    {
                        //10元的情况,最多10种可能
                        for (int d = 0; d <= 10; d++)
                        {
                            //20元的情况,最多5种可能
                            for (int e = 0; e <= 5; e++)
                            {
                                //50元的情况,最多2种可能
                                for (int f = 0; f <= 2; f++)
                                {
                                    if ((1 * a + 2 * b + 5 * c + 10 * d + 20 * e + 50 * f)== 100)
                                    {
                                        count++;
                                        Console.WriteLine("1*{0}+2*{1}+5*{2}+10*{3}+20*{4}+50*{5}=100",
                                        a, b, c, d, e, f);
                                    }
                                }
                            }
                        }
                    }
                }
            }
            Console.WriteLine("共有{0}种可能情况", count);    //count=4562
            Console.ReadKey();
        }

http://topic.csdn.net/u/20081016/14/8e1b21c7-dbc8-40ce-ba93-28c4cac4e461.html

 

类似;http://topic.csdn.net/t/20030712/23/2021573.html