在 Java 中查找笛卡尔积 [英] Finding cartesian product in Java
本文介绍了在 Java 中查找笛卡尔积的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想找到一组元素的笛卡尔积.这是一个例子
I want to find cartesian product of set of elements. Here's an example
示例 1:
sets : (ab) (bc) (ca)
笛卡尔积是:
abc aba acc aca bbc bba bcc bca
示例 2:
sets : (zyx) b c
笛卡尔积是:
zbc ybc xbc
所以我正在考虑一种在 Java 中执行的算法,它可以在开始时找到在编译时定义的特定数量组的笛卡尔积.
So I am thinking of an algorithm to execute in Java which can find cartesian product of particular amount of groups defined at compile time at the start.
推荐答案
您可以使用 Sets.cartesianProduct()
方法来自 Google 的 Guava 库 用于生成笛卡尔积:
You can use the Sets.cartesianProduct()
method from Google's Guava libraries to generate Cartesian products:
com.google.common.collect.Sets.cartesianProduct(Set[] yourSets)
要是一切都这么简单就好了!
If only everything was that easy!
这篇关于在 Java 中查找笛卡尔积的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文