Cod sursa(job #7422)

Utilizator damaDamaschin Mihai dama Data 21 ianuarie 2007 15:28:42
Problema Diviz Scor 80
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.25 kb
#include <stdio.h>
#include <ctype.h>
#define infinit 101
#define modul 30103


int n[201], k, a, b, c[251][151], sol, used[10][251][151];

int main()
{
	freopen("diviz.in","r",stdin);
	freopen("diviz.out","w",stdout);
	
	int i, j, rest, temp;
	char ch;
	
	scanf("%d%d%d", &k, &a, &b);
	
	while(!feof(stdin))
	{
		scanf(" %c ", &ch);
		if(isdigit(ch))
		{
			n[++n[0]] = ch - '0';
		}
	}
	
	c[0][0] = 1;
	
	for(i = 1; i <= n[0]; ++i) // pe care il iau acum
	{
		if(n[i])
		{
			for(j = i; j > 0; --j) // cate am pus
			{
					for(rest = 0; rest < k; ++rest) // restul aluia de dinainte
					{
						temp = (rest * 10 + n[i]) % k;
						c[j][temp] += c[j - 1][rest] - used[n[i]][j - 1][rest];
						c[j][temp] %= modul;
						used[n[i]][j - 1][rest] = c[j - 1][rest];
					}
			}
		}
		else
		{
			for(j = i; j > 1; --j) // cate am pus
			{
				for(rest = 0; rest < k; ++rest) // restul aluia de dinainte
				{
					temp = (rest * 10 + n[i]) % k;
					c[j][temp] += c[j - 1][rest] - used[n[i]][j - 1][rest];
					c[j][temp] %= modul;
					used[n[i]][j - 1][rest] = c[j - 1][rest];
				}
			}
		}
	}
	
	for(i = a; i <= b; ++i)
	{
		sol += c[i][0];
		sol %= modul;
	}
	
	printf("%d", sol);
	

	
	
	
	
	return 0;
}