Cod sursa(job #1026126)

Utilizator tudorv96Tudor Varan tudorv96 Data 11 noiembrie 2013 09:40:19
Problema 1-sir Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.61 kb
#include <fstream>
#include <iostream>
#include <algorithm>
using namespace std;

ifstream fin ("1-sir.in");
ofstream fout ("1-sir.out");

const int N = 260;
const int NN = N * (N + 1) / 2;
const int mod = 194767;

int d[2][NN], n, s;

int MOD (int x) {
	while (x >= mod)
		x -= mod;
	return x;
}

int main() {
	fin >> n >> s;
	s = abs(s);
	fin.close();
	if (s > n * (n + 1) / 2) {
		fout << 0;
		return 0;
	}
	d[0][0] = 1;
	int OLD = 0, NEW = 1;
	for (int i = 2; i <= n; ++i, swap (NEW, OLD))
		for (int j = 0; j <= n * (n + 1) / 2; ++j)
			d[NEW][j] = MOD (d[OLD][abs (j-i+1)] + d[OLD][abs (j+i-1)]);
	fout << d[OLD][s];
}