Cod sursa(job #1671888)

Utilizator harababurelPuscas Sergiu harababurel Data 2 aprilie 2016 11:23:22
Problema 1-sir Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.61 kb
#include <bits/stdc++.h>
#define nmax 260
using namespace std;

int n, s;
int dp[2][nmax*nmax];
bool line=1;

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

    f>>n>>s;

    s = abs(s);
    unsigned short maxS = n * (n-1) / 2;

    if(s > maxS) {
        g<<"0\n";
        return 0;
    }

    dp[!line][0] = 1;
    for(unsigned short i=2; i<=n; i++) {
        for(unsigned short targetS=0; targetS <= maxS; targetS++)
            dp[line][targetS] = (dp[!line][abs(targetS - (i-1))] + dp[!line][targetS + (i-1)]) % 194767;
        line = !line;
    }

    g<<dp[!line][s]<<"\n";

    return 0;
}