Cod sursa(job #1886333)

Utilizator dragos_vecerdeaVecerdea Dragos dragos_vecerdea Data 20 februarie 2017 20:31:34
Problema Diamant Scor 30
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.02 kb
#include <stdio.h>

using namespace std;
#define IMP 10000
FILE*fin = fopen("diamant.in", "r");
FILE *fout = fopen("diamant.out", "w");
int a[90000];
int b[90000];
int c[90000];
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;
    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;q++)
            {
                b[q]=a[q]%IMP;
                c[q]=a[q]%IMP;
            }
            for(int q=0;q<=2*smax-s;q++)
            {
                if(b[q+s]!=0) b[q]+=b[q+s]%IMP;

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