Cod sursa(job #635353)

Utilizator AndreiRSStatescu Andrei Rares AndreiRS Data 19 noiembrie 2011 10:48:51
Problema Dirichlet Scor 0
Compilator cpp Status done
Runda .com 2011 Marime 1.23 kb
#include <stdio.h>
#include <fstream>
#define tg (sw == 0 ? 1 : 0)
using namespace std;

const int dim = 1 << 19;
int N, T;
long long C, D[2][dim];

void back (int k, int b)
{
	if (k == N)
	{
		C++;
		return;
	}
	for (int i = 0; b+i <= k; i++)
	{
		back (k+1, b+i);
	}	
}

void dina1 ()
{
	int i, j, k, sw = 0;
	
	memset (D, 0, sizeof (D));
	D[sw][0] = 1;
	for (i = 1; i <= N; i++)
	{
		sw = tg;
		for (j = 0; j <= i; j++)
		{
			D[sw][j] = 0;
			for (k = max(j-i, 0); k <= j; k++)
				D[sw][j] += D[tg][k];	
		}
	}
	C = D[N&1][N];
}

void dina2 ()
{
	int i, j, k, sw = 0;
	
	memset (D, 0, sizeof (D));
	D[sw][0] = 1;
	for (i = 1; i <= N; i++)
	{
		sw = tg;
		D[sw][0] = 1;
		for (j = 1; j <= i; j++)
		{
			D[sw][j] = D[sw][j-1] + D[tg][j];	
			if (j-i > 0)
				D[sw][j] -= D[sw][j-i-1];
		}
	}
	C = D[N&1][N];
}


int main ()
{
	freopen ("dirichlet.in", "r", stdin);
	freopen ("dirichlet.out", "w", stdout);
	/*
	scanf ("%d", &T);
	while (T--)
	{
		scanf ("%d", &N); C = 0;
		
		back (1, 0);
		printf ("%lld\n", C);
		
		dina1 ();
		printf ("%lld\n", C);
		
		dina2 ();
		printf ("%lld\n", C);
	}	
	*/
	scanf ("%d", &N);
	dina2 ();
	printf ("%lld\n", C);
	
	return 0;
}