使用java列举所有给定数组中和为定值的组合
2024-10-08 20:55:44
import java.util.Arrays; public class SolveProb { static int[] arr = new int[];
static int index = ;// 记录当前
public SolveProb() { }
public static void numGroup(int[] arr, int start, int length, int sum) {
if (sum == ) {
for (int j = ; j < index; j++) {
System.out.print(arr[j]);
}
System.out.println();
} else {
for (int i = start; i < length; i++) {
arr[index++] = arr[i];
SolveProb.numGroup(arr, i + , length-, sum - arr[i]);
}
}
index--;
}
public static void main(String[] args) {
int[] arr = { , , , , , , , , };
Arrays.sort(arr);
int sum = ;
SolveProb.numGroup(arr, , arr.length, sum);
}
}
最新文章
- 前端性能优化--为什么DOM操作慢?
- xml和json的区别
- js string to int
- ws318 配置
- Essential Sublime Text Plugins
- 用大白话扯扯那";神奇";的面向对象编程思维(一)
- http请求参数中文乱码的问题
- 配置GitLab Push 自动触发Jenkins构建
- 设置PyCharm创建文件时自动添加头文件
- ubantu查看进程操作
- Android framework回想(2) sp 和 wp sp对象
- The type org.apache.commons.cli.Options cannot be resolved. It is indirectly referenced from required .class files
- ajax跨域请求在IE8中存在的问题
- PHP是什么?
- 俞昆20155335《网络对抗》MSF基础应用
- onethink后台登陆修改验证码!
- TCL基本语法
- (数据科学学习手札37)ggplot2基本绘图语法介绍
- NGUI 简单的背包系统
- (原創) Gvim 個人習慣常用設定 (vim)
热门文章
- 痢疾杆菌|SARS
- Python—插入排序算法
- jest 测试入门(一)
- Sex linkage
- Opencv笔记(十三)——图像的梯度
- 面试常见二叉树算法题集锦-Java实现
- 关于 Xpath 定位
- CondaHTTPError: HTTP 000 CONNECTION FAILED for url <;https://repo.anaconda.com/pkgs/main/win-64/repodata.json.bz2>; Elapsed: -
- Spring的@Transactional(readOnly=true)注解,对其效果进行测试
- cnn可视化 感受野(receptive field)可视化