Cod sursa(job #2480537)

Utilizator FunnyStockyMihnea Andreescu FunnyStocky Data 25 octombrie 2019 19:01:52
Problema Diamant Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.59 kb

/// M-a vazut femeia ta in oras instant m-a iubit
/// M-a vazut te-a parasit
/// Alta zdreanta n-ai gasit
/// Am scos-o pa zdreanta-n oras am iesit in papuci Gucci
/// Dupa date i-am dat papucii

#include <iostream>
#include <cstdio>

using namespace std;

const int MOD = 10000;
const int L = 44100 + 1;

int n, m, x, dp[2 * L], dp2[2 * L];
#define dp (dp + L)
#define dp2 (dp2 + L)

int main()
{
        freopen ("diamant.in", "r", stdin);
        freopen ("diamant.out", "w", stdout);

        cin >> n >> m >> x;

        if (abs(x) >= L)
        {
                cout << "0\n";
                return 0;
        }

        int sum = 0;
        dp[0] = 1;
        for (int i = 1; i <= n; i++)
                for (int j = 1; j <= m; j++)
                {
                        int y = i * j;
                        for (int x = -sum; x <= sum; x++)
                                if (dp[x])
                                {
                                        dp2[x] += dp[x]; if (dp2[x] >= MOD) dp2[x] -= MOD;
                                        dp2[x + y] += dp[x]; if (dp2[x + y] >= MOD) dp2[x + y] -= MOD;
                                        dp2[x - y] += dp[x]; if (dp2[x - y] >= MOD) dp2[x - y] -= MOD;
                                }
                        sum += y;
                        for (int x = -sum; x <= sum; x++)
                        {
                                dp[x] = dp2[x];
                                dp2[x] = 0;
                        }
                }
        cout << dp[x] << "\n";


        return 0;
}