Cod sursa(job #185710)

Utilizator luk17Luca Bogdan luk17 Data 25 aprilie 2008 22:04:41
Problema Diamant Scor 20
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.65 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;
if(st[top]<=1)
  st[top]++;

if(st[top]>1)
  top--;
  else
    if((top==n*m))
      {
      if((evalid(top)==x))
      nr=(nr+1)%10000;
      }
    else
     st[++top]=-2;

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