import java.util.ArrayList; import java.util.Collections; import java.util.Scanner; /** * * @author scache * */ public class Main { public static void main(String[] args) { Main p = new Main(); } public Main() { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int s = sc.nextInt(); int[] p = new int[n]; for(int i=0;i list; public void solve(int s, int[] p) { list = new ArrayList(); suf(s, p, p.length/2, 0, 0); Collections.sort(list); pre(s, p, 0, 0, 0); } private void pre(int s, int[] p, int n, int sum, int used){ if(sum>s) return; if(n==p.length/2){ int index = Collections.binarySearch(list, new ShoppingInfomation(s-sum, 0)); if(index<0) return ; for(int i=index;i>=0;i--){ if(list.get(i).price+sum==s) printResult(p, used+list.get(i).used); else break; } for(int i=index+1;is) return; if(n==p.length){ list.add(new ShoppingInfomation(sum, used)); return; } suf(s, p, n+1, sum+p[n], used|(1<<(p.length-n-1))); suf(s, p, n+1, sum, used); } private void printResult(int[] p, int used){ for(int i=p.length-1;0<=i;i--){ if(((used>>i)&1)==1){ System.out.print(p.length-i +" "); } } System.out.println(""); } private class ShoppingInfomation implements Comparable{ int price; int used; public ShoppingInfomation(int price, int used){ this.price = price; this.used = used; } @Override public int compareTo(ShoppingInfomation o) { return price-o.price; } } }