1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
|
// CODE 3____ problem when I combine them _________
#include<vector>
#include<stdio.h>
#include<stdlib.h>
using namespace std;
int part(int col_1, int &row_1, int **Res, int col_2, int row_2, vector<int>& v)
{
int i, f;
if(col_2<1) return 0;
v[row_2]=col_2;
row_1++;
for (i = 0; i < col_1; i++)
{
Res[i] = (int*)realloc(Res[i], row_1*sizeof(int));
Res[i][row_1-1]=0;
}
for (i = 0; i < col_2; i++)
Res[i][row_1-1]=v[i];
f=(row_2==0) ? 1 : v[row_2-1];
for(i=f; i<=col_2/2; i++)
{
v[row_2] = i;
part(col_1, row_1, Res, col_2-i, row_2+1, v);
}
}
int main()
{
int col_1, row_1, col_2, row_2, i, j, **Res;
col_1 = col_2 = 15;
row_1 = row_2 = 0;
Res = (int**)calloc( col_1, sizeof(int*));
vector<int> v(col_2);
part(col_1, row_1, Res, col_2, row_2, v);
for(i = 0; i < row_1; i++)
{
printf("\n");
for(j = 0; j < col_1; j++)
printf("%d ", Res[j][i]);
}
return 0;
}
|