Cod sursa(job #1275024)

Utilizator lacraruraduRadu Matei Lacraru lacraruradu Data 24 noiembrie 2014 17:46:39
Problema Diamant Scor 90
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.29 kb
#include <fstream>

using namespace std;

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

const int xmax = 44100;
const int decalaj = 44100;
const int modulo = 10000;
int n , m , x;
int diamante[xmax + decalaj + 1];

int main()
{
    int s = 0;

    in >> n >> m >> x;

    for(int i = 1 ; i <= n ; i++)
        for(int j = 1 ; j <= m ; j++)
            s += i * j;

    diamante[-s + decalaj] = 1;

    for(int i = 1 ; i <= n ; i++)
        for(int j = 1 ; j <= m ; j++)
        {
            for(int k = s; k >= -s ; k--)
            {
                if(k + i * j <= s)
                {
                    diamante[k + i * j + decalaj] += diamante[k + decalaj];
                    if(diamante[k + i * j + decalaj] >= modulo)
                        diamante[k + i * j + decalaj] -= modulo;
                }

                if(k + 2 * i * j <= s)
                {
                    diamante[k + 2 * i * j + decalaj] += diamante[k + decalaj];
                    if(diamante[k + 2 * i * j + decalaj] >= modulo)
                        diamante[k + 2 * i * j + decalaj] -= modulo;
                }
            }
        }

    if(x > s || x < -s)
    {
        out << "0\n";
        return 0;
    }

    out << diamante[x + decalaj];
    return 0;
}