Advertisement
Guest User

opencup G

a guest
Dec 11th, 2011
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.70 KB | None | 0 0
  1. #define _CRT_SECURE_NO_DEPRECATE
  2. #include <algorithm>
  3. #include <string>
  4. #include <set>
  5. #include <map>
  6. #include <vector>
  7. #include <queue>
  8. #include <iostream>
  9. #include <iterator>
  10. #include <cmath>
  11. #include <cstdio>
  12. #include <cstdlib>
  13. #include <sstream>
  14. #include <fstream>
  15. #include <ctime>
  16. #include <cstring>
  17. #pragma comment(linker, "/STACK:66777216")
  18. using namespace std;
  19. #define pb push_back
  20. #define ppb pop_back
  21. #define pi 3.1415926535897932384626433832795028841971
  22. #define mp make_pair
  23. //#define x first
  24. //#define y second
  25. #define pii pair<int,int>
  26. #define pdd pair<double,double>
  27. #define INF 1000000000
  28. #define FOR(i,a,b) for (int _n(b), i(a); i <= _n; i++)
  29. #define FORD(i,a,b) for(int i=(a),_b=(b);i>=_b;i--)
  30. #define all(c) (c).begin(), (c).end()
  31. #define SORT(c) sort(all(c))
  32. #define rep(i,n) FOR(i,1,(n))
  33. #define rept(i,n) FOR(i,0,(n)-1)
  34. #define L(s) (int)((s).size())
  35. #define C(a) memset((a),0,sizeof(a))
  36. #define VI vector <int>
  37. #define ll long long
  38. #define rp rept
  39. #define inf INF
  40. #define problem ""
  41. int n, m;
  42. char a[13][13];
  43. ll f[2][2000000];
  44. int pws[13];
  45. int vals[13];
  46. inline void add(int num, int mask, ll val) {
  47.     f[num][mask] += val;
  48.     if (f[num][mask] >= (ll)inf*inf) {
  49.         f[num][mask] -= (ll)inf *inf;
  50.     }
  51. }
  52. int main()
  53. {
  54.     pws[0] = 1;
  55.     for(int i = 1; i < 13; ++i) pws[i] = pws[i - 1]  * 3;
  56.     freopen(problem "life.in","r",stdin);
  57.     freopen(problem "life.out","w",stdout);
  58.     cin >> m >> n;
  59.     for(int i = 0; i < n; ++i)
  60.         for(int j = 0; j < m; ++j)
  61.             cin >> a[i][j];
  62.     int lim = pws[m - 1] * 3;
  63.     int cur = 0, nxt = 1;
  64.     f[0][0] = 1;
  65.     for(int i = 0; i < n; ++i)
  66.         for(int j = 0; j < m; ++j) {
  67.             for(int mask = 0; mask < lim; ++mask) {
  68.                 f[nxt][mask] = 0;
  69.             }
  70.             for(int mask = 0; mask < lim; ++mask) {
  71.                 if (!f[cur][mask]) continue;
  72.                 int x = mask;
  73.                 for(int t = 0; t < m; ++t) {
  74.                     vals[t] = x % 3;
  75.                     x /= 3;
  76.                 }
  77.                 bool can_put = 1;
  78.                 int put = mask;
  79.                 if (i > 0) {
  80.                     if (vals[0] == 1) can_put = false;
  81.                     else if (vals[0] == 0) put++;
  82.                 }
  83.                 if (j > 0) {
  84.                     if (vals[m - 1] == 1) can_put = false;
  85.                     else if (vals[m  -1] == 0) put += pws[m - 1];
  86.                 }
  87.                 put = put / 3  + 2 * pws[m - 1];
  88.                 if (can_put) {
  89.                     add(nxt, put, f[cur][mask]);
  90.                 }
  91.                 if (a[i][j] == 'B') {
  92.                     continue;
  93.                 }
  94.                 int black = 0;
  95.                 if (i > 0 && vals[0] == 2) {
  96.                     ++black;
  97.                 }
  98.                 if (j > 0 && vals[m - 1] == 2) {
  99.                     ++black;
  100.                 }
  101.                 if (black == 2) {
  102.                     continue;
  103.                 }
  104.                 add(nxt, mask / 3 + pws[m - 1] * black, f[cur][mask]);
  105.             }
  106.             swap(cur, nxt);
  107.         }
  108.     ll ans = 0;
  109.     for(int mask = 0; mask < lim; ++mask) {
  110.         ans += f[cur][mask];
  111.         if (ans >= (ll)inf *inf) {
  112.             ans -= (ll)inf*inf;
  113.         }
  114.     }
  115.     cout << ans << endl;
  116. }
  117.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement