Cod sursa(job #2139371)

Utilizator stefanchistefan chiper stefanchi Data 22 februarie 2018 14:35:27
Problema Diamant Scor 50
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.32 kb
#include <cstdio>

using namespace std;
const int limitastanga = - 44110;
const int limitadreapta = 44110;
const int Modulo = 10000;
int x,greutate;
int sirelemente[405],dp[2][3 * limitadreapta];

void preparation(int n , int m)
{
    int aux = 1;
    for(int i = 1 ; i <= n ; i++)
        for(int j = 1; j <= m ; j++)
            sirelemente[aux++]=i*j;
}

void backpack(int limita)
{
    int calitate = 0;
    int switchline = 1;
    for(int i = 1; i <= limita; i++)
    {
        for(int k = -greutate ; k <= greutate ; k++)
        {
            calitate = dp[!switchline][k + greutate];
            calitate = (calitate + dp[!switchline][greutate + sirelemente[i] + k])%Modulo;
            calitate =(calitate + dp[!switchline][greutate - sirelemente[i] + k])%Modulo;
            dp[switchline][greutate + k ] = calitate;
        }
        switchline = !switchline;
    }
}



int main()
{
    int n,m;
    freopen("diamant.in","r",stdin);
    freopen("diamant.out","w",stdout);
    scanf("%d %d %d",&n,&m,&x);
    if(x > limitadreapta || x < limitastanga)
    {
        printf("0\n");
        return 0;
    }
    greutate = (n * (n + 1) / 2)*(m * (m + 1) / 2);
    preparation(n,m);
    dp[0][greutate] = 1;
    backpack(n*m);
    printf("%d\n",dp[(n*m)%2][x+greutate]);
    return 0;
}