Cod sursa(job #1226512)

Utilizator paunmatei7FMI Paun Matei paunmatei7 Data 5 septembrie 2014 20:30:02
Problema 1-sir Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.6 kb
#include <cstdio>
#include <cmath>

#define NMAX 256
#define SMAX 256 * 257 / 2
#define Mod 194767

using namespace std;

int Dp[NMAX][SMAX];
int n, s, Smax;

int main(){
    freopen("1-sir.in", "r", stdin);
    freopen("1-sir.out", "w", stdout);
    scanf("%d %d", &n, &s);
    Smax = n * (n - 1) / 2;
    if(Smax < s){
        printf("0\n");
        return 0;
    }
    Dp[1][0] = 1;
    for(int i = 2; i <= n; ++i)
        for(int j = 0; j <= s; ++j)
            Dp[i][j] = (Dp[i - 1][(int)fabs(j - i + 1)] + Dp[i - 1][j + i - 1]) % Mod;
    printf("%d\n", Dp[n][s]);
    return 0;
}