iscsi

SRM 412 D1 250 ForbiddenStrings

Jul 28th, 2011
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.99 KB | None | 0 0
  1. #include <algorithm>
  2. #include <iostream>
  3. #include <sstream>
  4. #include <string>
  5. #include <vector>
  6. #include <queue>
  7. #include <set>
  8. #include <map>
  9. #include <cstdio>
  10. #include <cstdlib>
  11. #include <cctype>
  12. #include <cmath>
  13. using namespace std;
  14. typedef long long LL;
  15. #define FOR(k,a,b) for(int k(a); k < (b); ++k)
  16. #define REP(k,a) for(int k=0; k < (a); ++k)
  17.  
  18.  
  19. class ForbiddenStrings {
  20. public:
  21.     long long countNotForbidden(int n) {
  22.         if(n==1) return 3;
  23.         vector<vector<vector<LL> > > dp(30,vector<vector<LL> > (3,vector<LL>(3)));
  24.         REP(i,3)
  25.         REP(j,3)
  26.         {
  27.             dp[0][i][j]=1;
  28.         }
  29.         REP(i,29)
  30.         REP(j,3)
  31.         REP(k,3)
  32.         {
  33.             if(j==k)
  34.                 dp[i+1][j][k]+=dp[i][0][j]+dp[i][1][j]+dp[i][2][j];
  35.             else
  36.                 dp[i+1][j][k]+=dp[i][j][j]+dp[i][k][j];
  37.         }
  38.  
  39.         LL res=0;
  40.         REP(i,3)
  41.         REP(j,3)
  42.             res+=dp[n-2][i][j];
  43.         return res;
  44.     }
  45.  
  46. };
Advertisement
Add Comment
Please, Sign In to add comment