Cod sursa(job #178754)

Utilizator albuaAlbu Alexandru albua Data 15 aprilie 2008 08:37:26
Problema Teren Scor 20
Compilator c Status done
Runda Arhiva de probleme Marime 0.76 kb
#include <stdio.h>

FILE *f,*g;
int a[305][305],m,n,k;
long max;


void citire(void)
{
  int i,j;
  fscanf(f,"%d %d %d\n",&n,&m,&k);
  for(i=1;i<=n;i++)
    {
	  for(j=1;j<=m;j++)
	    fscanf(f,"%d",&a[i][j]);
	  fscanf(f,"\n");
	}
}

int verifica(int lj,int ld)
{
  int i,j,temp=0;
  for(i=1;i<=lj;i++)
    for(j=1;j<=ld;j++)
	  if(a[i][j]==1)
	    temp++;
  return temp;
}

void executa(int lj, int ld)
{
  int temp;
  temp=verifica(lj,ld);
  if(temp<=k)
    {
      if(lj*ld>max)
	  max=lj*ld;
    }
  else
    {
	  executa(lj-1,ld);
	  executa(lj,ld-1);
	}   
}

int main()
{
  f=fopen("teren.in","r");
  g=fopen("teren.out","w");
  citire();
  executa(n,m);
  fprintf(g,"%ld\n",max);
  fclose(f);  fclose(g);
  return 0;
}