#include using namespace std; int a[100][100]; int x[100], t[100], n, m; int PhanTich(int m, int n) { if (m == 0) { if (n == 0) a[m][n] = 1; else a[m][n] = 0; } else { if (m > n) a[m][n] = PhanTich(m - 1, n); else a[m][n] = PhanTich(m - 1, n) + PhanTich(m, n - m); } return a[m][n]; } void Show(int k) { cout << n << " = "; for (int i = 1; i < k; i++) { cout << x[i] << " + "; } cout << x[k] << endl; } int Try(int k) { for (int i = x[k - 1]; i <= ((n - t[k - 1]) / 2); i++) { x[k] = i; t[k] = t[k - 1] + i; Try(k + 1); } if (n - t[k - 1] <= m) { x[k] = n - t[k - 1]; Show(k); } } int main() { n = 5; m = 2; cout << "Co " << PhanTich(m, n) << " cach phan tich" << endl; for (int i = 0; i <= n; i++) x[i] = 0; x[0] = 1; t[0] = 0; Try(1); return 0; }