Cod sursa(job #2844153)

Utilizator robertanechita1Roberta Nechita robertanechita1 Data 3 februarie 2022 20:43:42
Problema Diamant Scor 80
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.85 kb
#include <bits/stdc++.h>
#define mod 10000

using namespace std;

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

int n, m, x, a[410], k, dp[3][90006];

/// obs : 200*399
///dp[i][j] - nr de diamante cu pana la poz i cu val j

int main()
{
    fin >> n >> m >> x;
    for(int i = 1; i <= n; i++)
        for(int j = 1; j <= m; j++)
            a[++k] = i*j;
    if(x > 45000 || x < -45000)
    {
        fout << "0\n";
        return 0;
    }
    x = x + 45000;
    dp[1][45000] = 1;
    int L = 0;
    for(int i = 1; i <= k; i++)
    {
        for(int j = 0; j <= 90000; j++)
        {
            dp[L][j] = (dp[1 - L][j + a[i]] + dp[1 - L][j]) % mod;
            if(j >= a[i])
                 dp[L][j] += (dp[1 - L][j - a[i]] % mod);
        }
        L = 1 - L;
    }
    fout << dp[1 - L][x] % mod;
    return 0;
}