The (k+1)th row of the pascal’s triangle is:
kC0, kC1, … kCk
Now, it’s easy to derive: C(n,r) = C(n,r-1) * (n-r+1)/r
Using this recursive relation, an iterative DP will yield the solution easily.
vector<int> Solution::getRow(int n)
{
vector<int> ans(n+1);
ans[0]=1;
for(int r=1; r<=n; r++)
{
ans[r]= (ans[r-1]*(n-(r-1)))/r;
}
return ans;
}