Cod sursa(job #984077)

Utilizator stefanzzzStefan Popa stefanzzz Data 13 august 2013 14:31:24
Problema 1-sir Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.59 kb
#include <fstream>
#define MAXS 40000
#define NRM 194767
using namespace std;
ifstream f("1-sir.in");
ofstream g("1-sir.out");

int n,s,pd[2][MAXS],act,mxj;

int ABS(int a){
    return (a>0)?(a):(-a);}

int main()
{
    int i,j;
    f>>n>>s;
    pd[0][0]=1;
    act=1;
    for(i=2;i<=n;i++){
        mxj=i*(i-1)/2;
        for(j=0;j<=mxj;j++){
            pd[act][j]=pd[1-act][j+i-1]+pd[1-act][ABS(j-i+1)];
            if(pd[act][j]>=NRM)
                pd[act][j]-=NRM;}
        act=1-act;}
    g<<pd[1-act][ABS(s)]<<'\n';
    f.close();
    g.close();
    return 0;
}