Cod sursa(job #1886363)

Utilizator dragos_vecerdeaVecerdea Dragos dragos_vecerdea Data 20 februarie 2017 20:42:24
Problema Diamant Scor 80
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.99 kb
#include <stdio.h>

using namespace std;
#define IMP 10000
FILE*fin = fopen("diamant.in", "r");
FILE *fout = fopen("diamant.out", "w");
int a[100000];
int b[100000];
int main()
{
    int n,m,k;
    fscanf(fin, "%d%d%d", &n, &m, &k);
    int smax=0;
    for(int i=1;i<=n;i++)
        for(int j=1;j<=m;j++)
    {
        smax+=(i*j);
    }
    a[smax]=1;
    b[smax]=1;
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=m;j++)
        {
            int s=i*j;
            for(int q=0;q<=2*smax-s;q++)
            {
                if(b[q+s]!=0) b[q]+=b[q+s]%IMP;
                b[q]%=IMP;

            }
            for(int q=2*smax;q>=s;q--)
            {
                if(a[q-s]!=0) b[q]+=a[q-s]%IMP;
                b[q]%=IMP;
            }
            for(int q=0;q<=2*smax;q++)
            {
                a[q]=b[q];
            }
        }
    }
    if(k>=-smax && k<=smax)fprintf(fout, "%d", a[k+smax]%IMP);
    else fprintf(fout, "0");
    return 0;
}