rouxQ @ 2020-03-30 11:09:45
这段代码在我本地跑样例正确,但是在luogu上跑出来5,(也因为这个问题90分),大佬们能看一下我的代码或者在您们本地跑一跑样例吗
#include <iostream>
#include <cstdio>
using namespace std;
int f[101][70][70];int sg[70],n,m,cnt,a[101];
int count(int x){
int s = 0;
while(x)
s++, x &= x - 1;
return s;
}
void Pre() {
for (int i = 0;i < (1 << m);i++)
if(!(i & (i << 1)) && !(i & (i << 2)))
sg[++cnt] = i;
return;
}
int main () {
cin >> n >> m;
char ch;
for (int i = 1;i <= n;i++) {
getchar();
for (int j = 1;j <= m;j++){
ch = getchar(); a[i] = (a[i] << 1) | (ch == 'P' ? 0 : 1);
}
}
/*if (n == 5 && m == 4){
cout << 6;
return 0;
}*///这里不加就是90分
Pre();
for (int i = 1;i <= cnt;i++)
if (!(sg[i] & a[1]))
f[1][i][0] = count(sg[i]);
for (int i = 1;i <= cnt;i++)
for (int j = 1;j <= cnt;j++)
if (!(sg[i] & sg[j]) && !(sg[i] & a[2]) && !(sg[j] & a[1]))
f[2][i][j] = max(f[2][i][j],f[1][j][0] + count(sg[i]));
for (int i = 3;i <= n;i++)
for (int j = 1;j <= cnt;j++)
if (!(a[i] & sg[j]))
for (int k = 1;k <= cnt;k++)
if (!(a[i - 1] & sg[k]))
for (int l = 1;l <= cnt;l++)
if (!(a[i - 2] & sg[l]))
if (!(sg[k] & sg[j]) && !(sg[k] & sg[l]) && !(sg[j] & sg[l]))
f[i][j][k] = max(f[i][j][k],f[i - 1][k][l] + count(sg[j]));
int Max = 0;
for (int i = 1;i <= cnt;i++)
for (int j = 1;j <= cnt;j++)
Max = max(Max,f[n][i][j]);
cout << Max;
return 0;
}
by GoldenFishX @ 2020-03-30 11:10:13
ee
by Enterprise_ @ 2020-03-30 11:12:57
@rouxQ 我这跑样例过了
by zzzzzgym @ 2020-04-10 22:20:54
同本地可以过,交到洛谷上90分
by Suuon_Kanderu @ 2020-07-18 10:32:36
@rouxQ 别用getchar,cin试试
by Suuon_Kanderu @ 2020-07-18 10:35:45
https://www.luogu.com.cn/record/35302431
过了
by Suuon_Kanderu @ 2020-07-18 10:35:50
qaq