我正在使用我创建的链接列表,其中包含一组数字作为数据.我需要找到一种方法来测试这个列表的每个可能的两组分区,为此,我需要将列表分成每个可能的两组组合.订单并不重要,会有重复.
For instance, for a list of numbers {1 4 3 1}, the possible splits are
{1} and {4, 3, 1}
{4} and {1, 3, 1}
{3} and {1, 4, 1}
{1} and {1, 4, 3}
{1, 4} and {3, 1}
{1, 3} and {4, 1}
{1, 1} and {4, 3}
Run Code Online (Sandbox Code Playgroud)
4个数字的列表并不难,但随着列表越来越大,事情变得越来越复杂,我在查看模式时遇到了麻烦.任何人都可以帮我找到一个算法吗?
编辑:
对不起,我没有看到这个问题.这是我到目前为止所尝试的.我的循环结构是错误的.当我在尝试常规数组后弄清楚我在做什么时,我将扩展算法以适合我的链表.
public class TwoSubsets
{
public static void main(String[] args)
{
int[] list = {1, 3, 5, 7, 8};
int places = 1;
int[] subsetA = new …Run Code Online (Sandbox Code Playgroud) 我是 Spring 和 Hibernate 的新手,并且尝试了所有我能找到的方法来解决这个问题,但没有成功。任何帮助将不胜感激。我目前正在关注一本书中的示例项目,并收到一条错误消息“GenerationTarget 在接受命令时遇到异常:通过 JDBC 语句执行 DDL 时出错”。我使用的是 MariaDB 数据库,我的 hibernate 方言是 org.hibernate.dialect.MySQL5InnoDBDialect。
导致此问题的查询是
alter table car drop foreign key FK2mqqwvxtowv4vddvtsmvtiqa2;
Run Code Online (Sandbox Code Playgroud)
如果我尝试直接在数据库中运行此查询,它工作正常。我将 ddl-auto 属性设置为 create-drop,所以当汽车表已被删除且不存在时,它可能会尝试执行此查询?我不确定为什么会这样做,或者如果这是问题的话如何关闭这种行为。
如果我将 ddl-auto 更改为验证或更新,则应用程序根本无法运行。如果我将其更改为创建,它工作正常并且不会出现错误。
通过 create-drop,应用程序确实连接到数据库并创建了我的所有表。表仍然按应有的方式定义,但错误仍然存在。
控制台输出:
2018-07-25 16:56:24.229 INFO 12414 --- [ restartedMain] c.p.cardatabase.CardatabaseApplication : Starting CardatabaseApplication on Northstar-2.local with PID 12414 2018-07-25 16:56:24.230 INFO 12414 --- [ restartedMain] c.p.cardatabase.CardatabaseApplication : No active profile set, falling back to default profiles: default
2018-07-25 16:56:24.278 INFO 12414 --- [ restartedMain] ConfigServletWebServerApplicationContext : Refreshing org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext@42e3f007: startup …Run Code Online (Sandbox Code Playgroud)