1. Memory problem

I have this program:
Code:
```#include <stdio.h>
#include <stdlib.h>
#define MAX 1000  /* Array limit */
#define oo 1000000000 /* "infinite" */

int percurso[MAX];
int cara=0,coroa=0;
int maxpeso=-1000000000; /* another infinite */
int in;
int ja_ta=0;
int somei=0;
void poe_na_fila(int x)
{
percurso[coroa]=x;
coroa++;
}

{
int i=0,soma=0;
somei=1;
for(i=0; i< coroa-1;i++)
return soma;
}

void max_peso(int source, int sink, int nodes, int j)
{
int num;
int u = 0, n = 0;
if ( ja_ta ) return;
if (j > nodes && source == in)
{
ja_ta = 1;
return;
}
else
{
if (source == sink) {
poe_na_fila(source);
}
else
{
if (j > nodes)
{
percurso[coroa] = 0;
coroa -= 1;
max_peso(percurso[coroa], sink, nodes, source + 1);
}
else
{
max_peso(source, sink, nodes, j + 1);
}
else
{
poe_na_fila(source);
max_peso(j, sink, nodes, 0);
}
}
}
if ( ja_ta ) return;
else
{
if (n > maxpeso)
maxpeso = n;
coroa = coroa - 1;
percurso[coroa] = 0;
coroa = coroa - 1;
max_peso(percurso[coroa], sink, nodes, source + 1);
}
}
}

main (int argc, char *argv[])
{
int noi,nof,peso,i,u,j,arcos,nos,inicio,fim;
inicio=fim=noi=nof=i=j=peso=arcos=nos=u=0;
FILE *fp;
fp=fopen(argv[1],"r");
if (fp==NULL)
printf("Impossível abrir o ficheiro %s", argv[1]);
else
{
fscanf(fp,"%d",&nos);
fscanf(fp,"%d",&arcos);
for(u=0;u<=nos;u++)
{
percurso[u]=0;
}
for(i=0; i<=nos;i++)
{
for(j=0;j<=nos;j++)
}
for(i=0;i<arcos;i++)
{

fscanf(fp,"%d %d %d", &noi,&nof,&peso);
}
fscanf(fp,"%d %d", &inicio, &fim);
in=inicio;
max_peso(inicio,fim,nos,0);
if(somei)
printf("%d\n",maxpeso);
else
printf("NA\n");
}

}```
It works perfectly,but my teachers are a bit nuts and will put inputs with more than 15Mb!The problem is i have a limit for my arrays or matrices. For example, for the adj matrice i need 2000000 bytes and most of them (half) are not used. I saw an example with 16 millions(!) possible combinations, that would mean a 16 million * 16 million matrice!My question is simple:
is there any way of using malloc or something like it,to alloc the necessary space for the adj and percurso arrays?16 million...

2. You better find a more efficient way to do it, because that would require almost an exobyte of memory (1 exobyte = 1 000 terabytes = 1 000 000 gigabytes).

3. The problem is that i´m supposed to work with the matrices...Daam...Any other ideas would be helpful...

4. Allocate an array dynamically, using the right dimensions. There's plenty of sample code on here for doing that...

5. Well, if you decided to move to C++ here's a dynamic array class that I've been using, you might interest in it.