Cod sursa(job #1318207)

Utilizator gabrielinelusGabriel-Robert Inelus gabrielinelus Data 15 ianuarie 2015 19:06:32
Problema 1-sir Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.71 kb
#include <cstdio>
#include <cstdlib>

#define supermax 32640
#define SMax 40000
#define MOD 194768

using namespace std;
int N,S,Smax;
int DP[SMax];

void Read()
{
    scanf("%d%d",&N,&S);
    if(S < 0)
        S *= -1;
    if(S > N*(N-1)/2){
        printf("0\n");
        exit(0);
    }
    Smax = N * (N - 1) / 2;
    S = Smax - S;
}

void Solve()
{
    int w;
    DP[0] = 1;
    for(int i = 1; i < N; ++i)
    {
        w = 2*i;
        for(int j = i*(i-1); j >= w; --j)
            DP[j] = (DP[j] + DP[j-w])%MOD;
    }
    printf("%d\n",DP[S]);
}

int main()
{
    freopen("1-sir.in","r",stdin);
    freopen("1-sir.out","w",stdout);

    Read();
    Solve();

    return 0;
}