Pagini recente » Cod sursa (job #1197799) | Cod sursa (job #1735821) | Cod sursa (job #3287211) | Cod sursa (job #1186570) | Cod sursa (job #2490724)
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
using namespace std;
ifstream fin("pod.in");
ofstream fout("pod.out");
const int modit = 9901;
vector<int> scand;
struct ma{
int w, h;
int va[21][21];
vector<ma> pcache;
ma(int w, int h) : w(w), h(h){
for(int x = 0; x < w; x++){
for(int y = 0; y < h; y++){
va[x][y] = 0;
}
}
}
ma(int s) : ma(s, s){}
ma mul(const ma & rhs){
ma r(rhs.w, h);
for(int x = 0; x < r.w; x++){
for(int y = 0; y < r.h; y++){
for(int k = 0; k < w; k++){
r.va[x][y] += va[k][y]*rhs.va[x][k];
r.va[x][y] %= modit;
}
}
}
return r;
}
void unit(){
for(int i = 0; i < w; i++){
va[i][i] = 1;
}
}
void pune(){
for(int i = 1; i < w; i++){
va[i][i-1] = 1;
}
va[0][0] = va[0][h-1] = 1;
}
void nupune(){
for(int i = 1; i < w; i++){
va[i][i-1] = 1;
}
}
void cacheme(){
pcache.push_back(*this);
}
ma raze(int p){
ma r(w,h);r.unit();
int c = 0;
for(int i = p; i > 0; i >>= 1){
if(i&1){
r = r.mul(pcache[c]);
}
c++;
if(pcache.size() <= c){
pcache.push_back(pcache.back().mul(pcache.back()));
}
}
return r;
}
};
int main(){
int n, m, k;
fin >> n >> m >> k;
scand.push_back(0);
for(int i = 0; i < m; i++){
int a;fin >> a;
scand.push_back(a);
}
sort(scand.begin(), scand.end());
ma mp(k), mnp(k);
mp.pune();mnp.nupune();
mp.cacheme();
ma a(k, 1);a.va[0][0] = 1;
for(int i = 1; i <= m; i++){
int del = scand[i]-scand[i-1]-1;
a = a.mul(mp.raze(del));
a = a.mul(mnp);
}
a = a.mul(mp.raze(n-scand.back()));
fout << a.va[0][0];
}