This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.
/*This is a java program to find the number of ways to write a given number as sum of numbers less than the number itself. We start with the number, number minus one is the next partition and so on, till all one’s are the last partition where we stop.*/
//This is a java program to find the number of ways to write a number as a sum of smaller than the number itself
importjava.util.Scanner;
publicclassNumberOf_Unique_Partitions
{
publicstaticvoidprint(int[]p,intn,intcount)
{
for(inti=0;i<n;i++)
System.out.print(p[i]+" ");
System.out.println();
intj;
for(j=0;j<n;j++)
{
if(p[j]==1)
continue;
else
break;
}
if(j==n)
System.out
.println("The number of ways to write a number as a sum of number smaller than itself is :"
+(count-1));
}
publicstaticvoidgenerateUniquePartition(intn)
{
int[]p=newint[n];
intk=0,count=0;
p[k]=n;
while(true)
{
count++;
print(p,k+1,count);
intrem_value=0;
while(k>=0&&p[k]==1)
{
rem_value+=p[k];
k--;
}
if(k<0)
return;
p[k]--;
rem_value++;
while(rem_value>p[k])
{
p[k+1]=p[k];
rem_value-=p[k];
k++;
}
p[k+1]=rem_value;
k++;
}
}
publicstaticvoidmain(Stringargs[])
{
System.out.println("Unique Partitioning of a given number");