# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1055416 | Hazard | Binaria (CCO23_day1problem1) | C++98 | 0 ms | 0 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
const int MOD = 1e6 + 3;
int count_strings(int N, int K, vector<int>& sms) {
int dp[N + 1][K + 1];
memset(dp, 0, sizeof(dp));
dp[0][0] = 1;
for (int i = 0; i < N; i++) {
for (int j = 0; j <= K; j++) {
if (i < K) {
dp[i + 1][j + 1] += dp[i][j];
dp[i + 1][j] += dp[i][j];
} else {
int target = sms[i - K + 1];
if (j >= target) {
dp[i + 1][j - target + 1] += dp[i][j];
}
dp[i + 1][j] += dp[i][j];
}
dp[i + 1][j + 1] %= MOD;
dp[i + 1][j] %= MOD;
}
}
int ans = 0;
for (int i = 0; i <= K; i++) {
ans += dp[N][i];
ans %= MOD;
}
return ans;
}
int main() {
int N, K;
cin >> N >> K;
vector<int> sms(N - K + 1);
for (int i = 0; i < N - K + 1; i++) {
cin >> sms[i];
}
int ans = count_strings(N, K, sms);
cout << ans << endl;
return 0;
}