Cod sursa(job #1572211)

Utilizator roxannemafteiuMafteiu-Scai Roxana roxannemafteiu Data 18 ianuarie 2016 20:01:29
Problema 1-sir Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.64 kb
#include <fstream>
//#include <cmath>
#include <cstdlib>

using namespace std;

const int nMax = 266;
const int sumMax = nMax * (nMax - 1) / 2;
const int MOD = 194767;

int N, S, D[nMax][sumMax];

int main() {
    ifstream fin("1-sir.in");
    ofstream fout("1-sir.out");

    fin >> N >> S;

    fin.close();

    S = abs(S);

    if(N * (N - 1) / 2 < S) {
        fout << 0;
        return 0;
    }

    D[1][0] = 1;
    for(int i = 2; i <= N; ++i)
            for(int j = 0; j <= i * (i - 1) / 2; ++j)
                D[i][j] = (D[i - 1][abs(j - (i - 1))] + D[i - 1][abs(j + (i - 1))]) % MOD;

    fout << D[N][S];

    fout.close();

    return 0;
}