Cod sursa(job #2789825)

Utilizator NeganAlex Mihalcea Negan Data 28 octombrie 2021 00:18:04
Problema Diamant Scor 80
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.99 kb
#include <bits/stdc++.h>

using namespace std;

ifstream fin("diamant.in");
ofstream fout("diamant.out");

int n, m, dp[2][100000], X, N;
int a[405];
int main()
{
    int i, j;
    fin >> n >> m >> X;
    if(X > (n * (n + 1) / 2) * (m * (m + 1) / 2))
    {
        fout << "0\n";
        return 0;
    }
    for(i = 1;i <= n;i++)
        for(j = 1;j <= m;j++)
            a[++N] = i * j;
    int nrmax = (n * (n + 1) / 2) * (m * (m + 1) / 2);
    int line = 0;
    dp[line][nrmax] = 1;
    for(line = 1,i = 1;i <= N;i++, line = 1 - line)
        for(j = -nrmax;j <= nrmax;j++)
        {
            dp[line][j + nrmax] = dp[1 - line][j + nrmax];
            if(j  >= -nrmax + a[i])
                dp[line][j + nrmax] += dp[1 - line][j - a[i] + nrmax];
            if(j + a[i] <= nrmax)
                dp[line][j + nrmax] += dp[1 - line][j + a[i] + nrmax];
            dp[line][j + nrmax] %= 10000;
        }
    fout << dp[1 - line][X + nrmax] % 10000 << "\n";
    return 0;
}