Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- ifstream in("parcare1.in");
- ofstream out("parcare1.out");
- #define STATE pair<int,bool>
- const int NMAX = 20;
- const int MOD = 666013;
- typedef long long I64;
- STATE dp[NMAX+2][NMAX+2][NMAX+2][NMAX+2];
- STATE aux[NMAX+2][NMAX+2][NMAX+2][NMAX+2];
- STATE coloana[NMAX+2][NMAX+2];
- int N, H, Q;
- inline void add(STATE &a, STATE b)
- {
- if( b.second == 0 ) return ;
- a.second = 1;
- a.first = (a.first + b.first) % MOD;
- }
- STATE mult(STATE s, int x)
- {
- if( s.second == 0 ) return s;
- s.first = 1LL * s.first * x % MOD;
- return s;
- }
- int main()
- {
- in >> N >> H >> Q;
- dp[0][0][0][0] = {1, 1};
- for( int ind = 1; ind <= N; ++ind ) {
- int g;
- in >> g;
- for( int i = 0; i <= NMAX; ++i ) for( int x = 0; x <= NMAX; ++x )
- for( int j = 0; j <= NMAX; ++j ) for( int y = 0; y <= NMAX; ++y )
- aux[i][x][j][y] = dp[i][x][j][y];
- for( int i = 0; i <= NMAX; ++i ) for( int x = 0; x <= NMAX; ++x )
- for( int j = 0; j <= NMAX; ++j ) for( int y = 0; y <= NMAX; ++y ) {
- dp[i][x][j][y] = aux[i][x][j][y];
- if( i >= g && x > 0 )
- add(dp[i][x][j][y], mult(aux[i - g][x - 1][j][y], x));
- if( j >= g && y > 0 )
- add(dp[i][x][j][y], mult(aux[i][x][j - g][y - 1], y));
- }
- }
- for( int i = 0; i <= NMAX; ++i ) for( int x = 0; x <= NMAX; ++x )
- for( int j = 0; j <= NMAX; ++j ) for( int y = 0; y <= NMAX; ++y )
- add(coloana[i][j], dp[i][x][j][y]);
- I64 ans = 1;
- for( int i = 1; i <= Q; ++i ) {
- int pos;
- in >> pos;
- if( coloana[pos - 1][H - pos].second == 0 ) {
- ans = 0;
- break;
- }
- ans = 1LL * ans * coloana[pos - 1][H - pos].first % MOD;
- }
- out << ans << '\n';
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement