/*
* Description: Finding Comb(n,k)
* Dynamic Programming Technique
*
* DP Based on recursive formula.
* C(n,k) = 1 if k == 0 or n == k
* C(n,k) = C(n-1,k-1) + C(n-1,k)
*
*/
#include <bits/stdc++.h>
#define LLI long long int
#define SIZE 101
using namespace std;
LLI C[SIZE][SIZE], i, j, n, k;
int main(int argc, char const *argv[]) {
n = 6;
k = 4;
C[ 0 ][ 0 ] = 1;
for(i = 1; i <= n; ++i) {
for(j = 0; j <= i; ++j) {
if(0 == j || i == j) C[i][j] = 1;
else
C[i][j] = C[i-1][j-1] + C[i-1][j];
}
}
for(i = 0; i <= n; ++i) {
for(j = 0; j <= i; ++j) {
cout<<C[i][j]<<" ";
}
cout<<endl;
}
cout<<C[n][k];
return 0;
}
LyoKICogRGVzY3JpcHRpb246IEZpbmRpbmcgQ29tYihuLGspCiAqIER5bmFtaWMgUHJvZ3JhbW1pbmcgVGVjaG5pcXVlCiAqCiAqIERQIEJhc2VkIG9uIHJlY3Vyc2l2ZSBmb3JtdWxhLgogKiBDKG4saykgPSAxIGlmIGsgPT0gMCBvciBuID09IGsKICogQyhuLGspID0gQyhuLTEsay0xKSArIEMobi0xLGspCiAqCiAqLwoKI2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CiNkZWZpbmUgTExJIGxvbmcgbG9uZyBpbnQKI2RlZmluZSBTSVpFIDEwMQoKdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCkxMSSBDW1NJWkVdW1NJWkVdLCBpLCBqLCBuLCBrOwoKaW50IG1haW4oaW50IGFyZ2MsIGNoYXIgY29uc3QgKmFyZ3ZbXSkgewoKICBuID0gNjsKICBrID0gNDsKCiAgQ1sgMCBdWyAwIF0gPSAxOwoKICBmb3IoaSA9IDE7IGkgPD0gbjsgKytpKSB7CgogICAgICBmb3IoaiA9IDA7IGogPD0gaTsgKytqKSB7CgogICAgICAgIGlmKDAgPT0gaiB8fCBpID09IGopIENbaV1bal0gPSAxOyAKICAgICAgICAKICAgICAgICBlbHNlCgogICAgICAgICAgIENbaV1bal0gPSBDW2ktMV1bai0xXSArIENbaS0xXVtqXTsKCiAgICAgIH0KICB9CgogIGZvcihpID0gMDsgaSA8PSBuOyArK2kpIHsKCiAgICAgIGZvcihqID0gMDsgaiA8PSBpOyArK2opIHsKCiAgICAgICAgY291dDw8Q1tpXVtqXTw8IiAiOwogICAgICB9CiAgICAgIGNvdXQ8PGVuZGw7CiAgfQoKICBjb3V0PDxDW25dW2tdOwoKICByZXR1cm4gMDsKfQo=