为啥交POJ挂了

P2704 [NOI2001] 炮兵阵地

DengDuck @ 2022-09-03 16:15:46

luogu 100pts

#include<bits/stdc++.h>
using namespace std;
long long n,m,a[105],cnt,dzh[105],f[105][105][105],ans;
char c;
int gx(long long x)
{
    int ans=0;
    while(x)ans++,x-=(x&(-x));
    return ans;
}
int main()
{
    cin>>n>>m;

    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=m;j++)
        {
            cin>>c; 
            a[i]<<=1;
            if(c=='H')a[i]++;
        }
    }
    dzh[++cnt]=0;
    for(int i=1;i<(1<<m);i++)
    {
        if((i&(i<<1))||(i&(i<<2))||(i&(i>>1))||(i&(i>>2)))continue;
        dzh[++cnt]=i;
    }
    for(int i=1;i<=cnt;i++)
    {
        if(dzh[i]&a[1])continue;
        f[1][i][0]=gx(dzh[i]);
    }

    for(int i=1;i<=cnt;i++)
    {
        if((dzh[i]&a[2]))continue;
        for(int j=1;j<=cnt;j++)
        {
            if((dzh[i]&dzh[j])||(dzh[j]&a[1]))continue;
            f[2][i][j]=gx(dzh[j])+gx(dzh[i]);               
        }

    }
    for(int i=3;i<=n;i++)   
    {
        for(int j=1;j<=cnt;j++)
        {
            if((dzh[j]&a[i]))continue;
            for(int k=1;k<=cnt;k++)
            {
                if((dzh[j]&dzh[k])||(dzh[k]&a[i-1]))continue;
                for(int k2=1;k2<=cnt;k2++)  
                {
                    if((dzh[j]&dzh[k2])||(dzh[k]&dzh[k2])||(dzh[k2]&a[i-2]))continue;
                    f[i][j][k]=max(f[i][j][k],f[i-1][k][k2]+gx(dzh[j]));
                }       
            }
        }
    }                      
    for(int i=1;i<=cnt;i++)
    {
        for(int j=1;j<=cnt;j++)
        {
            ans=max(ans,f[n][i][j]);
        }
    }       
    cout<<ans<<endl;
}

by hejianxing @ 2022-09-03 16:17:56

poj不能用万能头啊鸭子


by DengDuck @ 2022-09-03 16:18:44

@hejianxing 改成iostream了


by DengDuck @ 2022-09-03 16:27:46

还是过不了


|