#include <iostream>
using namespace std;
struct numarmare
{
unsigned char C[501];
int n;
};
numarmare A[501][501];
void aduna(numarmare A, numarmare B, numarmare &S)//s=a+b
{ int i,t,c,p;
if(A.n<B.n)
{ p=B.n;//nr max de cifre
for(i=A.n+1;i<=B.n;i++) A.C[i]=0;//completez cu 0
}
else { p=A.n;//nr max de cifre
for(i=B.n+1;i<=A.n;i++) B.C[i]=0;//completez cu 0
}
t=0;
for(i=1;i<=p;i++)
{
c=A.C[i]+B.C[i]+t; //adun cifra cu cifra
S.C[i]=c%10;//restul se pune
t=c/10;//catul e transport
}
if(t==1)// a ramas transport
{
p++;//avem cu o cifra mai mult
S.C[p]=t;
}
S.n=p;
}
void afisare(numarmare A)
{
for(int i=A.n;i>=1;i--)
cout<<(int)A.C[i];
}
int main()
{
int k,n;
cin>>n>>k;
A[0][0].n=1;
A[0][0].C[1]=1;
for(int i=1;i<=n;i++)
for(int j=0;j<=i;j++)
if(j==0) { A[i][j].n=1; A[i][j].C[1]=1;}
else aduna(A[i-1][j-1],A[i-1][j],A[i][j]);
afisare(A[n][k]);
return 0;
}
|