Pro_Rexxar @ 2019-06-23 09:55:05
不知道为什么就对了2个点
评测记录
#include<bits/stdc++.h>
using namespace std;
int n,m,cnt,a[101],state[61],sum[61];
long long ans,f[101][61][61];
char s[15];
int main()
{
scanf("%d%d",&n,&m);
for (int i=1;i<=n;i++)
{
scanf("%s",s);
int j=0;
while (s[j]!=0)
{
a[i]=(a[i]<<1)+((s[j]=='P')?1:0);
j++;
}
}
for (int i=0;i<=(1<<m)-1;i++)
{
if (i&(i<<1)) continue;
if (i&(i<<2)) continue;
state[++cnt]=i;
for (int j=i;j;j=j>>1)
if (j&1) sum[cnt]++;
}
for (int i=1;i<=cnt;i++)
{
if ((state[i]||a[1])>a[1]) continue;
f[1][i][0]=sum[i];
}
if (n==1)
{
for (int i=1;i<=cnt;i++)
{
if ((state[i]||a[1])>a[1]) continue;
ans=max(ans,f[1][i][0]);
}
printf("%lld\n",ans);
return 0;
}
for (int i=1;i<=cnt;i++)
{
if ((state[i]||a[2])>a[2]) continue;
for (int j=1;j<=cnt;j++)
{
if ((state[i]||a[1])>a[1]) continue;
if (state[i]&state[j]) continue;
f[2][i][j]=max(f[2][i][j],f[1][j][0]+sum[i]);
}
}
if (n==2)
{
for (int i=1;i<=cnt;i++)
{
if ((state[i]||a[2])>a[2]) continue;
for (int j=1;j<=cnt;j++)
{
if ((state[i]||a[1])>a[1]) continue;
if (state[i]&state[j]) continue;
ans=max(ans,f[2][i][j]);
}
}
printf("%lld\n",ans);
return 0;
}
for (int i=3;i<=n;i++)
for (int j=1;j<=cnt;j++)
{
if ((state[j]||a[i])>a[i]) continue;
for (int k=1;k<=cnt;k++)
{
if ((state[k]||a[i-1])>a[i-1]) continue;
for (int l=1;l<=cnt;l++)
{
if ((state[l]||a[i-2])>a[i-2]) continue;
if (state[k]&state[l]) continue;
if (state[j]&state[l]) continue;
if (state[j]&state[k]) continue;
f[i][j][k]=max(f[i][j][k],f[i-1][k][l]+sum[i]);
}
}
}
for (int i=1;i<=cnt;i++)
{
if ((state[i]||a[n])>a[n]) continue;
for (int j=1;j<=cnt;j++)
{
if ((state[i]||a[n-1])>a[n-1]) continue;
if (state[i]&state[j]) continue;
ans=max(ans,f[n][i][j]);
}
}
printf("%lld\n",ans);
return 0;
}
by 言和YanHe @ 2019-06-23 10:19:27
头像名字好评
by Pro_Rexxar @ 2019-06-23 15:30:01
@HFOI菠萝 然而现在牧狗标准基本打不了
by Pro_Rexxar @ 2019-06-23 16:30:17
太醉了
把有些地方的j改成i
最重要的是把数的或运算打成了 | |
by Dawn_Chase @ 2019-06-23 16:31:05
@牧中无人224 先%为敬
by Pro_Rexxar @ 2019-06-23 16:31:08
另外我同学没有特判n为1的情况也过了
强烈要求加强数据