2道算法题, 无限级分类数据库

来源:互联网 发布:tester软件 编辑:程序博客网 时间:2024/05/29 17:31

Q: 有1,2,2,3,4,5六个数,要求输出他们组合的全排列,4不能在第三位,5和3不能相邻?

A:C# code

public static void Main() { char[] number = new char[] { '1', '2', '2', '3', '4', '5' }; Func(number, 0, number.Length - 1); Console.WriteLine(list.Count); foreach (String s in list) { Console.Write(s + " "); } } public static List<string> list = new List<string>(); public static void Func(char[] n, int beg, int end) { if (beg == end) { string result = new string(n); if (result[2] == '4') return; if (result.Contains("35") || result.Contains("53")) return; list.Add(result); return; } for (int i = beg; i <= end; i++) { Swap(n, beg, i); Func(n, beg + 1, end); Swap(n, beg, i); } } public static void Swap(char[] n, int a, int b) { char temp = n[a]; n[a] = n[b]; n[b] = temp; }


关于本题的其他参考: 
http://rjx2008.javaeye.com/blog/339645 
http://www.javaeye.com/topic/55873 
http://blog.csdn.net/qianling3439/archive/2008/08/07/2781041.aspx 

Q: 算法:最长升序降序序列,7 5 6 8 10 7 9 3 8 7 4 1 8 9 4,则最长的升序序列为5, 6, 8, 10,最长的降序序列为8,7,4,1 ?

A:

 

Q: 无限级分类数据库设计及节点查找?

A: http://blog.csdn.net/amandag/archive/2009/12/16/5021126.aspx

原创粉丝点击