Cod sursa(job #1120859)

Utilizator Theorytheo .c Theory Data 25 februarie 2014 10:28:33
Problema 1-sir Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.64 kb
#include <fstream>
#include <cstring>
#include <cmath>

using namespace std;

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

const int NMAX = 260;
const int MOD = 194767;

int N; int S; int D[2][NMAX * NMAX];

int abs(int x){ return x > 0 ? x : -x;}

int main() {

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

    int act = 0;
    D[0][0] = 1;
    for(int i = 2; i <= N; ++i) {
        act = !act;
        for(int j = 0; j <= S; ++j)
            D[act][j] = (D[!act][j + i - 1] + D[!act][abs(j - i + 1)]) % MOD;
    }

    fout << D[act][S] << '\n';
    return 0;
}