Algorithm that creates in a systematic form, matrix with zero-one elements
First of all I would try to avoid all the matrix operations like trimming, joining, etc.
And instead just find a function that tells what value is on each position
bool tell(int x, int y, int K);

This would of course require more mathematical skill then programming, but you might eventually end up doing just this:
arma::mat P;
int maxY = K * (K-1) / 2
for (int y = 0; y &lt; maxY; ++y) {
  for (int x = 0; x &lt; K; ++x) {
    P.set(x, y, tell(x, y, K) ? 1 : 0)
  }
}

If tell(x,y) has O(1) complexity, this will probably be faster.
Another option that I can think of is similar, but more iterative.
Fill the topmost KxK part of the matrix with the pattern.
Then another (K-1)x(K-1) part of the metrix, fill with the (K-1) pattern while filling the last column with zeroes.
then another part of size (K-2)x(K-2) fill with pattern of size K-2 while filling the last two columns with zeroes.
And so on and so on until trying to fill pattern 0x0 where you terminate.
But you'll end up on something similar to the previous
int Y = 0;
for (int step = K; step &gt; 0; --step) {
  for (int y = 0; y &lt; step; ++y, ++Y) {
    for (int x = 0; x &lt; step; ++x) {
      P.set(x, Y, tell(x, y) ? 1 : 0)
    }
    for (int r = step; r &lt; K; ++r) {
      P.set(r, Y, 0)
    }
  }
}

here the tell function actually becomes quite trivial and third parameter is not even needed
bool tell(int x, int y)
{
  return x &gt;= y;
}

Whether the tell function for the first implementation is possible in O(1) and how to do it I leave to you and the mathematician inside of you :)