Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <string>
- using namespace std;
- int n, m;
- int dp[1001][2];
- bool s[1000];
- #ifdef EVAL
- ifstream in("input.txt");
- ofstream out("output.txt");
- #else
- istream &in(cin);
- ostream &out(cout);
- #endif
- int main()
- {
- string a;
- in >> m >> n >> a;
- for (int i = 0; i < m; i += 1)
- {
- s[i] = a[i] == '1';
- }
- dp[0][0] = 1;
- for (int i = 1; i <= n; i += 1)
- {
- if (i < m)
- {
- dp[i][0] = (dp[i-1][0] + dp[i-1][1]) % 2011;
- dp[i][1] = (dp[i-1][0] + dp[i-1][1]) % 2011;
- }
- else
- {
- dp[i][s[0]] = 0;
- for (int j = 1; j < m; j += 1)
- {
- dp[i][s[0]] += dp[i-j][!s[j]];
- dp[i][s[0]] %= 2011;
- }
- dp[i][!s[0]] = (dp[i-1][0] + dp[i-1][1]) % 2011;
- }
- }
- out << (dp[n][0] + dp[n][1]) % 2011 << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement