0-9选6个数加起来等于33的排列组合,数字可以重复。
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。
简单粗暴的排列算法:
public class BruteForceArrangement {
public static void main(String[] args) {
for (int a = 0; a < 10; a++)
for (int b = 0; b < 10; b++)
for (int c = 0; c < 10; c++)
for (int d = 0; d < 10; d++)
for (int e = 0; e < 10; e++)
for (int f = 0; f < 10; f++)
if (a + b + c + d + e + f == 33)
System.out.printf("%d%d%d%d%d%d\n", a, b, c, d, e, f);
}
}
简单粗暴的组合算法:
public class BruteForceCombination {
public static void main(String[] args) {
for (int a = 0; a < 10; a++)
for (int b = a; b < 10; b++)
for (int c = b; c < 10; c++)
for (int d = c; d < 10; d++)
for (int e = d; e < 10; e++)
for (int f = e; f < 10; f++)
if (a + b + c + d + e + f == 33)
System.out.printf("%d%d%d%d%d%d\n", a, b, c, d, e, f);
}
}