Cod sursa(job #941405)

Utilizator DaNutZ2UuUUBB Bora Dan DaNutZ2UuU Data 18 aprilie 2013 18:49:35
Problema 1-sir Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.74 kb
#include <iostream>
#include <fstream>
#include <cstdlib>
#define DN 260
#define MOD 194767

using namespace std;

ifstream f("1-sir.in"); ofstream g("1-sir.out");


int dp[4][DN * DN];

int main()
{
    int n;
    long long s;

    f >> n >> s;
    if(s < 0)
        s =- s;
    int smax = n * (n - 1) / 2;
    if(s > smax)
    {
        g<<0;
        return 0;
    }

    bool p=1;
    dp[1][0]=1;
    for(int i=2;i<=n;++i)
        {
            for(int sum=0;sum<=smax;++sum)
            {
                dp[!p][sum]=dp[p][sum+i-1]+dp[p][abs(sum-i+1)];

                if(dp[!p][sum]>=MOD)
                    dp[!p][sum]-=MOD;
            }
            p=!p;
        }
    g<<dp[p][s];

    return 0;
}