zoukankan      html  css  js  c++  java
  • 从数列1,2,3.......n 中 随意取几个数,使其和等于 m

      //从数列1,2,3.......n 中 随意取几个数,使其和等于 m
      
            public static void Print(int n, int m, List<int> list = null)
            {
                if (n < 1 || m < 1)
                {
                    return;
                }

                for (int i = 1; i <= n; i++)
                {
                    if (i < m)
                    {
                        List<int> childList = new List<int>();

                        if (list != null)
                        {
                            childList.AddRange(list);
                        }
                        childList.Add(i);

                        Print(i - 1, m - i, childList);
                    }
                    else if (i == m)
                    {
                        if (list != null)
                        {
                            foreach (int j in list)
                            {
                                Console.Write("{0} + ", j);
                            }

                            Console.WriteLine("{0}", m);
                        }
                    }
                }
            }

  • 相关阅读:
    5.22 css和基本选择器
    5.21http网页基础
    ArrayList类源码浅析(二)
    ArrayList类源码浅析(一)
    Long类源码浅析
    Integer类源码浅析
    JDK中String类的源码分析(二)
    JDK中String类的源码分析(一)
    Struts2漏洞修复总结
    [LeetCode]-011-Longest Common Prefix
  • 原文地址:https://www.cnblogs.com/dasydong/p/3280970.html
Copyright © 2011-2022 走看看