If duplicate values are allowed :: import java.io.BufferedReader; import java.io.InputStreamReader;
public class PartionNumber { public static void main(String[] args) { System.out.println("Enter the number"); InputStreamReader ifn = new InputStreamReader(System.in); BufferedReader buf = new BufferedReader(ifn); try{ String n =buf.readLine(); int number = Integer.parseInt(n); int i=-1; functionPartion(number,i); System.out.println("0 "+number); }catch(Exception e){ e.printStackTrace(); } } private static void functionPartion(int number,int a) { a=a+1; if(number!=0){ System.out.println(number+ " " +a); functionPartion(number-1, a); } } } Thanks and many regards, Sreeprasad On Sun, Feb 6, 2011 at 7:29 PM, Wei.QI <qiw...@gmail.com> wrote: > public static ArrayList<ArrayList<Integer>> Partition(int val, int start, > int size) { > > ArrayList<ArrayList<Integer>> r = new ArrayList<ArrayList<Integer>>(); > > if (start * size > val) { > return null; > } > > if(size == 1) > { > r.add(new ArrayList<Integer>()); > r.get(0).add(val); > return r; > } > > for (int i = start; i <= val/size; i++) { > ArrayList<ArrayList<Integer>> tr = Partition(val - i, i, size - 1); > if (tr != null) { > for (int j = 0; j < tr.size(); j++) { > ArrayList<Integer> subr = tr.get(j); > subr.add(i); > } > r.addAll(tr); > } > } > return r; > > } > > On Sun, Feb 6, 2011 at 7:51 AM, Gajendra Dadheech <gajju3...@gmail.com>wrote: > >> Write a function to print all unique partitions on n tht are of size m. >> eg: n=10, m=4. it should print 7 1 1 1, 6 2 1 1, 5 3 1 1, 3 3 2 2,, so on >> >> >> >> Thanks and regards, >> Gajendra Dadheech >> hi >> >> -- >> You received this message because you are subscribed to the Google Groups >> "Algorithm Geeks" group. >> To post to this group, send email to algogeeks@googlegroups.com. >> To unsubscribe from this group, send email to >> algogeeks+unsubscr...@googlegroups.com. >> For more options, visit this group at >> http://groups.google.com/group/algogeeks?hl=en. >> > > -- > You received this message because you are subscribed to the Google Groups > "Algorithm Geeks" group. > To post to this group, send email to algogeeks@googlegroups.com. > To unsubscribe from this group, send email to > algogeeks+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/algogeeks?hl=en. > -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.