题目链接
回溯
import java.util.*;
import java.math.*;
public class Main {
public static int[] a=new int[99];
public static int b;
public static int dx[]={1,-1,0,0},dy[]={0,0,-1,1};
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
b=sc.nextInt();
Arrays.fill(a,1);
dfs(1,b);
//System.out.println(1);
}
public static double d(int x1,int y1,int x2,int y2){
double a1=(x1-x2)*(x1-x2);
double a2=(y1-y2)*(y1-y2);
return Math.sqrt(a1+a2) ;
}
public static void dfs(int cur,int n){
//System.out.println(2);
for(int i=a[cur-1];i<=n;i++){
//System.out.println(i+" "+b);
if(i<b){
a[cur]=i;
n=n-i;
if(n==0)
f(cur);
else
dfs(cur+1,n);
n+=i;
}
}
}
public static void f(int t){
for(int i=1;i<=t-1;i++)
System.out.print(a[i]+"+");
System.out.println(a[t]);
}
}