Cod sursa(job #2617532)

Utilizator popoviciAna16Popovici Ana popoviciAna16 Data 21 mai 2020 21:46:05
Problema 1-sir Scor 80
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.7 kb
#include <fstream>
using namespace std;

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

int dp[2][40000];
//dp[i][j] = numarul de siruri de lungime i pe care le pot forma cu suma in modui j / 2

const int r = 194767;

inline int abs(int x)
{
    if (x < 0)
        return -x;
    return x;
}

int main()
{
    int n, i, j, smax, s;
    fin >> n >> s;
    if (s < 0)
        s = -s;
    if (s > n*(n-1)/2)
    {
        fout << 0;
        return 0;
    }
    smax = n*(n-1)/2;
    dp[0][0] = 1;
    for (i = 1; i<n; i++)
        for (j = 0; j<=smax; j++)
            dp[i&1][j] = (dp[(i-1)&1][j+i] + dp[(i-1)&1][abs(j-i)])%r;
    fout << dp[(n-1)&1][s];
    return 0;
}