Cod sursa(job #2574277)

Utilizator popoviciAna16Popovici Ana popoviciAna16 Data 5 martie 2020 21:15:45
Problema Diamant Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.88 kb
#include <fstream>
using namespace std;

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

const int c = 44600;
const int r = 10000;
int v[401];
int dp[2][2*44600+1];

int main()
{
    int smax = 0, n, m, i, j, x, l;
    fin >> n >> m >> x;
    for (i = 1; i<=n; i++)
        for (j = 1; j<=m; j++)
        {
            smax = smax + i*j;
            v[(i-1)*m+j] = i*j;
        }
    if (x < 0)
        x = -x;
    if (x > smax)
    {
        fout << 0;
        return 0;
    }
    for (l = 0, i = 1; i<=n*m; i++, l = 1-l)
    {
        for (j = -smax; j<=smax; j++)
        {
            dp[l][j+c] = dp[1-l][j+c];
            dp[l][j+c] += dp[1-l][j+c-v[i]];
            dp[l][j+c] += dp[1-l][j+c+v[i]];
            dp[l][j+c] %= r;
        }
        dp[l][v[i]+c]++;
        dp[l][-v[i]+c]++;
    }
    if (x == 0)
        dp[1-l][x+c]++;
    fout << dp[1-l][x+c]%r;
    return 0;
}