Cod sursa(job #974301)

Utilizator narcis_vsGemene Narcis - Gabriel narcis_vs Data 16 iulie 2013 19:24:21
Problema Diamant Scor 80
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.82 kb
#include <fstream>

#define In "diamant.in"
#define Out "diamant.out"
#define Smax 44700
#define MOD 10000
#define abs(x) ((x)>(0)?(x):(-(x)))
using namespace std;
int Dp[2][Smax+2], N, M, S, row;
inline void Read()
{
    ifstream f(In);
    f>>N>>M>>S;
    S = abs(S);
    f.close();
}

inline void Solve()
{
    int i, j, k = (N*M*(N+1)*(M+1)>>2), X;
    if(S>k)
    {
        S = 0;
        return ;
    }
    X = S+k;
    Dp[0][0] = 1;
    for(i = 1;i <= N;++i)
        for(j = 1 ;j <= M; ++j)
            for(k = 0,row ^= 1;k <= X; ++k)
                Dp[row][k] = (Dp[row^1][k] + Dp[row^1][k+i*j] + Dp[row^1][abs(k-(i*j))])%MOD;
}

inline void Write()
{
    ofstream g(Out);
    g<<Dp[row][S]<<"\n";
    g.close();
}


int main()
{
    Read();
    Solve();
    Write();
    return 0;
}