用1,2,5分的面额,组成10元(100分)的方法有多少种?
注:只在C#中用for循环做?

解决方案 »

  1.   

    参考下面这个帖子:
    http://topic.csdn.net/u/20081016/14/8e1b21c7-dbc8-40ce-ba93-28c4cac4e461.html
      

  2.   

    三元一次方程,用罗列法,很简单
    1*x + 2*y + 5*z = 100
        struct result
        {
            public int x;
            public int y;
            public int z;
        }        public List<result> cal()
            {
                List<result> resultList = new List<result>();
                result res= new result();
                for(int i = 0; i < 21; i++)
                {
                    res.z = i;
                    for(int j = 0; j < 51; j++)
                    {
                        res.y = j;
                        for(int m = 0; m < 101; m++)
                        {
                            res.x = m;
                            if(5 * i + 2 * j + m = 100)
                            {
                                resultList.Add(res);
                            }
                        }
                    }
                }
                return resultList;
            }
      

  3.   

    static void Main()
    {
       int x = 0;
       for (double i = 0.1; i < 1; i += 0.1)
          for (double j = 0.2; j < 1; j += 0.2)
              for (double m = 0.5; m < 1; m += 0.5)
                  if ((i + j + m) == 1.0)
                  {
                       x++;
                       Console.WriteLine("方法{0}: {1} + {2} + {3} = 1元",
                          x, i, j, m);
                  }
    }