Why dp approach is not working

#include
using namespace std;
long long int a[100000][100000]={0};

int main(){

a[0][0]=1;
a[1][0]=1;
a[1][1]=1;
for(int i=0;i<100000;i++){
	a[i][0]=1;
}
for(int i=2;i<100000;i++){
	for(int j=1;j<=i;j++){
		if(j<i){
			a[i][j]=a[i-1][j]+a[i-1][j-1];
			
		}
		else{
			a[i][j]=1;
		}
			
	}
}

int t;
cin>>t;
while(t–){
int n,m;
cin>>n>>m;
cout<<a[n-1][m-1]<<endl;
}

}

hello @coe17b014
because it is taking too much memory 100000 X 100000 array size consumes too much memory.

try O(1) space approacch.

1 Like