Cod sursa(job #2490595)

Utilizator CyborgSquirrelJardan Andrei CyborgSquirrel Data 10 noiembrie 2019 15:54:12
Problema Pod Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.5 kb
#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];
	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 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 idk(){
		for(int i = 0; i < w; i++){
			va[i][i] = 1;
		}
	}
	void kdi(){
		for(int i = 1; i < w; i++){
			va[i-1][i] = 1;
		}
		va[0][0] = va[w-1][0] = 1;
	}
	ma raze(int p){
		ma r(w,h);r.idk();
		ma t = *this;
		for(int i = p; i > 0; i >>= 1){
			if(i&1){
				r = r.mul(t);
			}
			t.mul(t);
		}
		return r;
	}
	void deb(){
		for(int y = 0; y < h; y++){
			for(int x = 0; x < w; x++){
				cout << va[x][y] << " ";
			}
			cout << "\n";
		}
	}
};

int main(){
	int n, m, k;
	fin >> n >> m >> k;
	for(int i = 0; i < m; i++){
		int a;fin >> a;
		scand.push_back(a);
	}
	sort(scand.begin(), scand.end());
	
	ma pa(k,k);pa.idk();
	ma ta(k,k);ta = pa.raze(scand[0]-1);
	ma ra(k,k);ra.kdi();
	for(int i = 1; i < m; i++){
		int del = scand[i]-scand[i-1];
		ta = ta.mul(ra);
		ta = ta.mul(pa.raze(del));
	}
	fout << (ta.va[0][0]+ta.va[k-1][0]) % modit;
}