Advertisement
Guest User

Untitled

a guest
Nov 21st, 2011
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.37 KB | None | 0 0
  1. #include <cstdio>
  2. #include <climits>
  3. #include <cstdlib>
  4. #include <cstring>
  5. #include <cmath>
  6. #include <cctype>
  7. #include <cassert>
  8. #include <ctime>
  9.  
  10. #include <iostream>
  11. #include <utility>
  12. #include <algorithm>
  13. #include <limits>
  14.  
  15. #include <vector>
  16. #include <string>
  17. #include <set>
  18. #include <map>
  19. #include <list>
  20. #include <queue>
  21. #include <deque>
  22. #include <bitset>
  23. #include <stack>
  24.  
  25. #define mp(x,y) make_pair(x,y)
  26. #define pb(x) push_back(x)
  27. #define fs first
  28. #define sc second
  29. #define sz(x) (int((x).size()))
  30. #define all(x) ((x).begin()),((x).end())
  31. #define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
  32. #define fab(i,a,b) for(int (i)=(a);(i)<=(b);(i)++)
  33.  
  34. using namespace std;
  35.  
  36. const double eps = 1e-10, inf = 1e10;
  37. typedef long long ll;
  38.  
  39. int dp[1010][1010], n, m;
  40. char s[1100];
  41.  
  42. int main()
  43. {
  44.     //freopen("input.txt","r",stdin);
  45.     //freopen("output.txt","w",stdout);
  46.  
  47.     scanf("%d %d\n%s\n", &m, &n, s);
  48.  
  49.     int inizio = s[0]-'0';
  50.  
  51.     fab(i,1,n)
  52.     {
  53.         if (i < m)
  54.         {
  55.             dp[i][0] = 1;
  56.             rep(r,i-1) dp[i][0] = (dp[i][0]*2) % 2011;
  57.             dp[i][1] = dp[i][0];
  58.         }
  59.         else
  60.         {
  61.             dp[i][1-inizio] = (dp[i-1][0] + dp[i-1][1]) % 2011;
  62.             dp[i][inizio] = 0;
  63.             fab(j,1,m-1) dp[i][inizio] = (dp[i][inizio] + dp[i-j][1-int(s[j]-'0')]) % 2011;
  64.         }
  65.     }
  66.  
  67.     printf("%d\n", (dp[n][0]+dp[n][1]) % 2011);
  68.     return 0;
  69. }
  70.  
  71.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement