所有二元组合的名单对一些在Java中组合、名单、Java

2023-09-11 02:17:31 作者:久疚

我工作的一个项目涉及动态规划和我打这个微不足道的小事,请大家帮帮忙。

I am working on a project involving "Dynamic Programming" and am struck on this trivial thing, please help.

假如我拿4作为输入,我想显示是这样的:0000 1111

Suppose I take 4 as an input, I want to display something like: 0000 to 1111

但是,如果我输入5,我想要显示像:00000到11111等等

But, if I input 5, I want to display like: 00000 to 11111 and so on.

在此先感谢,

修改:请不要发布问我为code。这不是一个家庭作业问题,我不需要任何code,只是告诉我的逻辑是,我会很高兴。

EDIT: Please don't post asking me for the code. This is not a homework problem and I don't need any code, just tell me the logic for it and I would be happy.

EDIT2 :WTH正在发生的事情#1,我没有问任何你写code给我吗?我想谁downvoted到upvote它的人。什么是点这个论坛,如果我不能帮忙?

EDIT2: WTH is happening with Stackoverflow, did I ask any of you to write code for me? I want the person who downvoted to upvote it. What is a point of this forum if I can't for help?

与我分享的逻辑。我们可以讨论,我不需要code这一点。

Share the logic with me. We can discuss and I do not require the code for this.

EDIT3 :在这里,我张贴了code,我试过了。我希望这个满足所有谁在想我还没有尝试过任何人。

EDIT3: Here I am posting the code which I tried. I hope this "SATISFIES" all the people who were thinking I have not tried anything.

import java.util.ArrayList;

公共类RegularInvestigator {

public class RegularInvestigator {

公开的ArrayList createCombinations(ArrayList中listOfFlightNumbers){

public ArrayList createCombinations(ArrayList listOfFlightNumbers) {

ArrayList<String> result = new ArrayList<String>();

for(int i = 1; i < listOfFlightNumbers.size(); i++) {

  String binaryEqvivalent = Integer.toBinaryString(i);System.out.println(binaryEqvivalent);
  String element = "";

  for(int j = 0; j < binaryEqvivalent.length(); j++)
    if(binaryEqvivalent.charAt(j) == '1')
      element += listOfFlightNumbers + " ";

  result.add(element.substring(0, element.length() - 1));
}

return result;

}

private String getContent(ArrayList<String> flight) {
String temp = "";

for(int i = 0; i < flight.size() - 1; i++)  temp += flight.get(i) + " ";

temp += flight.get(flight.size() - 1);

return temp;

}

私人的ArrayList removeElementAtIndex(ArrayList中飞行,INT位置){

private ArrayList removeElementAtIndex(ArrayList flight, int position) {

ArrayList<String> res = new ArrayList<String>();

for(int i = 0; i < flight.size(); i++) {
  if(i != position) res.add(flight.get(i));
}

return res;

} }

EDIT4 :谢谢phoxis,PengOne,杰里棺材oliholz​​您的宝贵答案:)

EDIT4: Thank you phoxis, PengOne, Jerry Coffin and oliholz for your valuable answers :)

推荐答案

获取输入 N 计数I = 0 (2 ^ N) - 1 的每个值我位掩码的每一位我和显示。

Get input n Count from i=0 to (2^n) - 1 for each value of i bitmask each bit of i and display.