Cod sursa(job #185691)

Utilizator luk17Luca Bogdan luk17 Data 25 aprilie 2008 20:48:16
Problema Diamant Scor 20
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.73 kb
#include<stdio.h>
int n,m,st[1000],top,nr=0;;
long long x;
long long sum=0;
long long evalid(int top)
{
int i;
long long s=0;
for(i=1;i<=top;i++)
    {
    if(i%m==0)
    s+=st[i]*(i/m)*m;
    else
      s+=st[i]*(i/m+1)*(i%m);
    }
return s;
}

int main()
{
int cand;
freopen("diamant.in","r",stdin);
freopen("diamant.out","w",stdout);
scanf("%d %d %lld",&n,&m,&x);
top=1;
st[top]=-2;
while(top>0)
{
cand=0;
while(!cand&&st[top]<1)
  {
  st[top]++;
sum= evalid(top);
  if (sum<=x)
   cand=1;
else
   cand=0;
  }
if(cand==0)
  top--;
  else
    if((top==n*m))
      {
      if((evalid(top)==x))
      nr=(nr+1)%10000;
      }
    else
     st[++top]=-2;

}
printf("%d\n",nr);
return 0;
}