蒟蒻求救

P2704 [NOI2001] 炮兵阵地

斯茂 @ 2019-01-05 19:58:24

20分RE

#include <cstdio>
#include <iostream>
#include <cstring>
using namespace std;
string s[105];
int ok[27], cnt;
int d[105][27][27][27];
int bt[1024];
int n, m;
void init()
{
  int i, j, k, l;
  for(i = 0; i < 105; i++)
    for(j = 0; j < 27; j++)
      for(k = 0; k < 27; k++)
        for(l = 0; l < 27; l++)
          d[i][j][k][l] = -1e9;
}
bool fit(int x, int S)
{
  int i;
  for(i = 1; i <= m; i++)
    if(s[x][m + 1 - i] == 'H' && ((S >> (i - 1)) & 1))
      return 0;
  return 1;
}
int main(int argc, char **argv)
{
    int i, j, k, l, M, ans = 0;
    init();
    cin >> n >> m;
    for(i = 1; i < (1 << m); i++)
      bt[i] = bt[i >> 1] + (i & 1);
    s[0] = " ";
    for(i = 1; i <= m; i++)
      s[0] += "H";
    for(i = 1; i <= n; i++)
    {
      cin >> s[i];
      s[i] = " " + s[i];
    }
    for(i = 0; i < (1 << m); i++)
      if(!(i & (i >> 1)) && !(i & (i >> 2)))
        ok[++cnt] = i;
    for(i = 1; i <= cnt; i++)
      if(fit(1, ok[i]))
      {
        d[1][i][1][1] = bt[ok[i]];
      }
    for(i = 2; i <= n; i++)
      for(j = 1; j <= cnt; j++)
        for(k = 1; k <= cnt; k++)
          for(l = 1; l <= cnt; l++)
          if(!(ok[j] & ok[k]) && !(ok[j] & ok[l]) && !(ok[k] & ok[l]) && fit(i, ok[j]) && fit(i - 1, ok[k]) && fit(i - 2, ok[l]))
            for(M = 1; M <= cnt; M++)
              d[i][j][k][l] = max(d[i][j][k][l], bt[ok[j]] + d[i - 1][k][l][M]);
    for(i = 1; i <= cnt; i++)
      for(j = 1; j <= cnt; j++)
        for(k = 1; k <= cnt; k++)
          ans = max(ans, d[n][i][j][k]);
    cout << ans << endl;
    return 0;
}

by namespace_std @ 2019-01-05 20:16:52

应该是哪个数组开小了

你试试

100 10
PPPPPPPPPP
PPPPPPPPPP
...(*100)
PPPPPPPPPP

by namespace_std @ 2019-01-05 20:22:43

@韩沛煊 把所有27改成65


by 斯茂 @ 2019-01-05 20:24:38

为啥,有用的状态在m=10的时候只有26个awa


by 斯茂 @ 2019-01-05 20:27:43

Oh

好像是我算错了......


|