Cod sursa(job #987372)

Utilizator cosmyoPaunel Cosmin cosmyo Data 20 august 2013 15:43:38
Problema 1-sir Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.95 kb
#include <iostream>
#include <fstream>
#include <vector>
#include <cmath>
using namespace std;
const int N = 252;
const int MOD = 194767;
vector<int> curr(N * N), previous(N * N);
int n, s;

int main()
{
    ifstream fin("1-sir.in");
    ofstream fout("1-sir.out");
    fin >> n >> s;
    s = abs(s);
    int maxS = n * (n - 1);
    maxS /= 2;
    if(s > maxS)
    {
        fout << 0 << '\n';
    }

    previous[0] = 1;
    for(int i = 2; i <= n; ++i)
    {

        for(int j = 0; j <= maxS; ++j)
        {
            curr[j] += previous[abs(j - (i - 1))] + previous[j + (i - 1)];
            while(curr[j] >= MOD)
            {
                curr[j] -= MOD;
          //  fout << curr[j] << ' ';
        }

      //  fout << '\n';
        for(int j = 0; j <= maxS; ++j)
        {
            previous[j] = curr[j];
            curr[j] = 0;
        }
    }

    fout << previous[s] << '\n';

    return 0;
}