Pagini recente » Cod sursa (job #2546591) | Cod sursa (job #2642043) | Cod sursa (job #663849) | Cod sursa (job #1236704) | Cod sursa (job #847223)
Cod sursa(job #847223)
#include <cstring>
#include <fstream>
#include <algorithm>
using namespace std;
const int MOD = 9901;
int N, M, K;
int Val[1002];
int now[22][22], todo[22][22];
int M1[22][22], M2[22][22], M3[22][22];
long long auxres[22][22];
void inm(int A[][22], int B[][22], int rows)
{
for (int i = 1; i <= rows; ++i)
for (int j = 1; j <= K; ++j)
{
auxres[i][j] = 0;
for (int k = 1; k <= K; ++k)
auxres[i][j] += 1LL * A[i][k] * B[k][j];
}
for (int i = 1; i <= rows; ++i)
for (int j = 1; j <= K; ++j)
{
if (auxres[i][j] >= MOD) auxres[i][j] %= MOD;
A[i][j] = auxres[i][j];
}
}
void power(int (*A)[22], int B)
{
memcpy(M1, A, sizeof(M1));
for (int i = 0; (1LL << i) <= B; ++i)
{
if ((1LL << i) & B)
inm(now, M1, 1);
inm(M1, M1, K);
}
}
int main()
{
ifstream fin("pod.in");
ofstream fout("pod.out");
fin >> N >> M >> K;
for (int i = 1; i <= M; ++i)
fin >> Val[i];
sort(Val + 1, Val + M + 1);
if (Val[M] == N)
{
fout << 0 << '\n';
fin.close();
fout.close();
return 0;
}
++M, Val[M] = N;
now[1][K] = 1;
for (int i = 1; i <= K - 1; ++i)
todo[i + 1][i] = 1;
todo[K][K] = 1;
todo[1][K] = 1;
for (int i = 1; i <= M; ++i)
{
power(todo, Val[i] - Val[i - 1]);
if (i != M) now[1][K] = 0;
}
fout << now[1][K] << '\n';
fin.close();
fout.close();
}