65,211
社区成员
发帖
与我相关
我的任务
分享#include <iostream>
using namespace std;
int n;
int a[100];
void fuckXiaoDong(int sum, int step, int begin)
{
if (sum == 0)
{
for (int i = 0; i < step; ++i)
{
cout << a[i] << ' ';
}
cout << endl;
}
else if (sum > 0)
{
for (int i = n; i >= 1; --i)
{
if (i <= begin)
{
a[step] = i;
fuckXiaoDong(sum - i, step + 1, i);
}
}
}
}
int main()
{
cin >> n;
fuckXiaoDong(n, 0, n);
return 0;
}
#include <iostream>
using namespace std;
void F(int n,int count,int depth)
{
if (1 == count)
cout << n << " ";
else
{
int j = 0;
int m = n - count + 1;
while (m-j > m/2)
{
for (int c = 1;c <= j+1;c++)
{
if (m + j + 1 <= n)
{
if ((c > 1 && c != j+1) || c==1)
{
F(m,1,2);
F(j + 1,c,2);
for (int i = 1;i <= count - 1 - c;i++)
{
if (m+j+1+i <= n)
F(1,1,2);
}
if (depth == 1)
cout << endl;
}
}
}
j++;
}
}
}
void main()
{
int n;
cin >> n;
cout << n << endl;
for (int i = 2;i <= n;i++)
{
F(n,i,1);
}
}#include <iostream.h>
int fun(int i,int j,int sum)
{
if (j!=1)
{
for (int i=1;i<sum;i++)
{
for (int j=sum;j>0;j--)
{
if (sum==i+j)
{
cout<<j<<"\t"<<i<<endl;
fun(i,j,j);
}
}
}
}
else
return 1;
return 0;
}
void f(int n)
{
fun(1,n,n);
}
void main()
{
int n;
cin>>n;
f(n);
}