Cod sursa(job #1181048)

Utilizator ioalexno1Alexandru Bunget ioalexno1 Data 1 mai 2014 18:40:23
Problema Diamant Scor 100
Compilator cpp Status done
Runda Teme Pregatire ACM Unibuc 2013 Semestrul 2 Marime 0.89 kb
#include <cstdio>
#define N 100001
#define mod 10000
using namespace std;
int sum,n,m,val,sol[2][N];
inline int abs(int x)
{
if(x<0)return -x; else return x; return 0;
}
void read()
{ int i,j;
freopen("diamant.in","r",stdin); scanf("%d %d %d",&n,&m,&val); fclose(stdin);
for(i=1;i<=n;++i)
    for(j=1;j<=m;++j)
        sum+=i*j;
}
void solve()
{ int p,u,i,z,j,h;
sol[0][0]=1; p=0; u=1;
for(i=1;i<=n;++i)
   for(j=1;j<=m;++j)
        {
        z=p; p=u; u=z;
        for(h=0;h<=sum;++h)
            sol[p][h]=(sol[u][h]+sol[u][h+i*j]+sol[u][abs(h-i*j)])%mod;
        }
}
void write()
{
freopen("diamant.out","w",stdout);
if(abs(val)>sum)printf("0");
    else {
           int x=n*m;
           if(x%2==1) printf("%d",sol[1][abs(val)]);
           else  printf("%d",sol[0][abs(val)]);
        }
}
int main()
{
read();
solve();
write();
return 0;
}
#undef N
#undef mod