假设有一些不固定长度的数组
比如 
{"a","b","c",..........}
{"1","2","3",..........}这些数组的数目不固定, 比如有3组,4组甚至更多现在要得到所有数组中字符的组合(每个数组中的每一个元素和其他数组中的一个元素构成一个组合,有几个个数组,这个组合就有几个元素)
比如 
a,1,....  
a,2,.....
........
b,1,....
b,2,......
..............
请问要怎么计算?还有如何储存它们到数据库, 
然后根据指定的元素得到这个组合

解决方案 »

  1.   

    一个数组一个表,联合select出来就好了,不需要神马算法
      

  2.   

    这问题又冒出来了google“C#笛卡尔积算法”如果不想google那么看下面http://topic.csdn.net/u/20110610/13/D1924231-0A45-4826-AC2A-7BBCFCB9FC93.html
      

  3.   

    http://topic.csdn.net/u/20110606/13/b41f8542-9996-4494-9bf2-313ac784a44b.html
      

  4.   

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;namespace ConsoleApplication1
    {
        static class Enumerable
        {
            public static IEnumerable<IEnumerable<TSource>> Combo<TSource>(this IEnumerable<IEnumerable<TSource>> source, IEnumerable<TSource> second)
            {
                foreach (var i in second)
                {
                    foreach (var j in source)
                    {
                        List<TSource> list = new List<TSource>();
                        list.Add(i);
                        yield return j.Concat(list);
                    }
                }
            }        public static IEnumerable<IEnumerable<TSource>> StartCombo<TSource>(this IEnumerable<TSource> first)
            {
                foreach (var i in first)
                {
                    List<TSource> list = new List<TSource>();
                    list.Add(i);
                    yield return list;
                }
            }
        }    class Program
        {
            static void Main(string[] args)
            {
                List<List<string>> list = new List<List<string>>()
                {
                    new List<string>() { "a" },
                    new List<string>() { "c", "d" },
                    new List<string>() { "e", "f", "g" },
                    new List<string>() { "h", "i" },
                    new List<string>() { "j" }
                };
                var result = list.Skip(1).Aggregate(list.First().StartCombo(), (serials, current) => serials.Combo(current), x => x).ToList();
                result.ForEach(x => { x.ToList().ForEach(y => Console.Write(y + " ")); Console.WriteLine(); });
            }
        }
    }
    a c e h j
    a d e h j
    a c f h j
    a d f h j
    a c g h j
    a d g h j
    a c e i j
    a d e i j
    a c f i j
    a d f i j
    a c g i j
    a d g i j
      

  5.   

    http://topic.csdn.net/u/20110610/13/D1924231-0A45-4826-AC2A-7BBCFCB9FC93.htmlhttp://topic.csdn.net/u/20110606/13/b41f8542-9996-4494-9bf2-313ac784a44b.html和9楼的方法都可以  请问那一种效率高呢?还有它们怎么样在数据库中进行呢保存, 我这里对每一个组合都对应一组参数 ,它们怎样进行保存好?
      

  6.   


    这种写法我就得比较优雅
    我能不能在 "a c e h j" 这种输出结果中,插入我需要的字符呢?
    比如变成 " a =衣服 c=裤子 e=袜子 h=鞋子 j=帽子"