Cod sursa(job #1221837)

Utilizator iordache.bogdanIordache Ioan-Bogdan iordache.bogdan Data 21 august 2014 16:20:47
Problema 1-sir Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.65 kb
#include <fstream>
#define DIMN 260
#define mod 194767

using namespace std;

ifstream f ("1-sir.in");
ofstream g ("1-sir.out");

int S, Smax, n;

int D[2][DIMN*DIMN];

inline int modul (int x) {
    return ( x<0 ? -x : x );
}

int main () {
    f >> n >> S;
    S = modul(S);
    Smax = n*(n-1)/2;
    if (S > Smax) {
        g << "0\n";
        return 0;
    }
    D[0][0] = 1;
    for (int i=2; i<=n; ++i) {
        for (int j=0; j<=Smax; ++j)
            D[1][j] = ( D[0][j+i-1] + D[0][modul(j-i+1)] ) % mod;
        for (int j=0; j<=Smax; ++j)
            D[0][j] = D[1][j];
    }
    g << D[0][S] << "\n";
    return 0;
}