原来不用vis数组也可哈哈,不用去去重了,更新版!

import java.io.*;
import java.util.*;
public class Main{
    static int m, n;
    static ArrayList<String> strList = new ArrayList<>();
    public static void main(String[] args) throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String str;
        while((str = br.readLine()) != null) {
            String[] ss = str.split(" ");
            n = Integer.parseInt(ss[0]);
            m = Integer.parseInt(ss[1]);
            dfs(0, 0, "");
            StringBuilder sb = new StringBuilder();
            for(String s : strList) {
                sb.append(s).append("\n");
            }
            System.out.print(sb.toString());
        }
    }
    
    static void dfs(int index, int sum, String str){
        if(sum == m) strList.add(str.trim());
        if(sum < m){
            for(int i = index; i < n && sum + i <= m; i++) {
                dfs(i + 1, sum + i + 1, str + (i + 1) + " ");
            }
        }
    }
}