相关疑难解决方法(0)

列表列表的所有组合

我基本上正在寻找一个python版本的组合List<List<int>>

给定一个列表列表,我需要一个新列表,它列出了列表之间所有可能的项目组合.

[[1,2,3],[4,5,6],[7,8,9,10]] -> [[1,4,7],[1,4,8],...,[3,6,10]]
Run Code Online (Sandbox Code Playgroud)

列表的数量是未知的,所以我需要一些适用于所有情况的东西.优点加分!

python combinations

210
推荐指数
6
解决办法
10万
查看次数

如何获得几个List <int>的所有组合

与上面的sugested解决方案不同,列表项只能为每一行显示一次.

这是我的水疗中心的预订系统.不同的员工可以进行不同的治疗

我有一个List<List<int>>.这些治疗师可以进行预约治疗.

每个清单(预订)都包含许多这样的整数(这些是可以执行预订的治疗师):

{1, 3, 6},  //Booking 1
{1, 2, 6},  //Booking 2
{1},        //Booking 3
{2,3}       //Booking 4
Run Code Online (Sandbox Code Playgroud)

我想看看所有可能的组合,其中数字只能出现在一个地方.对于上面的列表,两个可能的组合将是:

6,2,1,3或3,6,1,2

这是第一个组合:

  • 预订1:治疗师6
  • 预订2:治疗师2
  • 预订3:治疗师1
  • 预订4:治疗师3

希望这会让问题更加清晰.

c#

9
推荐指数
2
解决办法
3191
查看次数

如何获得具有不同数量元素的n个数组的所有可能组合?

我有一些在编程时未知的数组,可能是3或4或7 ...每个数组都有一些元素,即

a={1 2 3 4}
b={6 7 5 2 1}
c={22 4 6 8 4 8 5 4}
d={....}
e, f, g, ...
Run Code Online (Sandbox Code Playgroud)

我希望通过从每个数组中抽取一个数字来获得所有可能的组合,例如一种情况是我从a中选择"1",从b中获取"7",从c获得第一个"8",d [3],e [ 5],......制作"1,7,8,d [3],e [5],......".不可能使用嵌套的for循环,因为我不知道编译时的数组数.如果已知例如4个数组(a,b,c,d),我可以使用4个循环:

for (int i = 0; i <= a.Length-1; i++)
{
   for (int j = 0; i <= b.Length-1; j++)
   {
      for (int k = 0; i <= c.Length-1; k++)
      {
         for (int m = 0; i <= d.Length-1; m++)
         {
            Response[f++] = a[i].toString()+","+b[j].toString()+","+c[k].toString()+","+d[m].toString();
         }
      }
   }
}
Run Code Online (Sandbox Code Playgroud)

但是对于不同数量的阵列,我什么都不知道.

c# arrays combinations

9
推荐指数
1
解决办法
3061
查看次数

找出给定长度的所有可能单词的好方法是什么

我正在尝试在C#中创建一个算法,它产生以下输出字符串:

AAAA
AAAB
AAAC
...and so on...
ZZZX
ZZZY
ZZZZ
Run Code Online (Sandbox Code Playgroud)

完成此任务的最佳方法是什么?

public static IEnumerable<string> GetWords()
{
    //Perform algorithm
    yield return word;
}
Run Code Online (Sandbox Code Playgroud)

c# string algorithm iterator

7
推荐指数
3
解决办法
5173
查看次数

可能的组合

我有一系列的列表

List<string>[] possibleLines;
Run Code Online (Sandbox Code Playgroud)

数组可以具有不同的大小,每个List <>可以具有不同数量的字符串.例如

  • List<string>[0] - 可以有字符串"first string","second string"
  • List<string>[1] - "第三弦","第四弦","第五弦"

我需要获得所有可能的组合,每个字符串必须来自不同的列表(数组大小可能不同).例如

  • "第一个字符串","第四个字符串"
  • "第一个字符串","第五个字符串"
  • "第二个字符串","第四个字符串"

等等.

.net c# arrays list

2
推荐指数
1
解决办法
179
查看次数

标签 统计

c# ×4

arrays ×2

combinations ×2

.net ×1

algorithm ×1

iterator ×1

list ×1

python ×1

string ×1