Cod sursa(job #2844135)

Utilizator robertanechita1Roberta Nechita robertanechita1 Data 3 februarie 2022 20:12:14
Problema Diamant Scor 20
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.78 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][80006];

/// 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[0][45000] = 1;
    for(int i = 1; i <= k; i++)
    {
        for(int j = 0; j <= x; j++)
            dp[1][j] = (dp[0][j + a[i]] + dp[0][j - a[i]] + dp[0][j]) % mod;
        for(int j = 0; j <= x; j++)
            dp[0][j] = dp[1][j];
    }
    fout << dp[0][x] % mod;
    return 0;
}