用Java查找笛卡尔积 [英] Finding cartesian product in Java

查看:135
本文介绍了用Java查找笛卡尔积的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想找到一组元素的笛卡尔积。这是一个例子

I want to find cartesian product of set of elements. Here's an example

example 1 :
sets :(ab) (bc) (ca)

笛卡尔积,


abc aba acc aca bbc bba bcc bca

abc aba acc aca bbc bba bcc bca



example 2 :
sets : (zyx) b c

笛卡尔积,


zbc ybc xbc

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)

如果一切都那么简单!

这篇关于用Java查找笛卡尔积的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆