Cod sursa(job #1390922)

Utilizator ericptsStavarache Petru Eric ericpts Data 17 martie 2015 14:04:40
Problema 1-sir Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.92 kb
#include <fstream>
#include <iostream>

using namespace std;

const int MOD = 194767;

int n, s;

int DP[2][32900];

int solve() {
    int mx = n * (n - 1) / 2;
    if(s > mx)
        return 0;

    DP[1][0] = 1;

    for(int i = 2 ; i <= n ; ++i) {
        int pp = i % 2;
        for(int j = 0 ; j <= s ; ++j) {

            DP[pp][j] = 0;

            int a = j - (i - 1),
                b = j + (i - 1);

            if(a < 0)
                a = -a;

            if(a <= s)
                DP[pp][j] += DP[!pp][a];

            if(b <= s)
                DP[pp][j] += DP[!pp][b];

            while(DP[pp][j] >= MOD)
                DP[pp][j] -= MOD;
        }
    }
    return DP[n % 2][s];
}

int main() {
    ifstream in("1-sir.in");
    in >> n >> s;
    if(s < 0)
        s = -s;
    in.close();

    ofstream out("1-sir.out");
    out << solve() << "\n";
    out.close();
}