求各位大佬帮帮忙

P2704 [NOI2001] 炮兵阵地

雪绮晶 @ 2018-08-25 11:23:14

样例都没过QAQ

@夜刀神十香ღ @AC我最萌

#include<stdio.h>
#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
int ans;
int dp[100][1005][1005],n,m;
char c;
int num[1005],s[1005];
int states,i;
int map[1005];
int count(int n) {
    int ans;
    while(n) {
        if(n&1)
            ans++;
        n>>=1;
    }
    return ans;
}
int main () {
    scanf("%d%d",&n,&m);
    for(i=1; i<=n; i++) {
        for(int j=1; j<=m; j++) {
            cin>>c;
            if(c=='H') {
                map[i]+=1<<j;
            }
        }
    }
    for(i=0; i<(1<<m); i++) {
        if(((i&(i<<1))==0)&&((i&(i<<2))==0)&&((i&(i>>1))==0)&&((i&(i>>2))==0)) {
            num[++states]=count(i);
            s[states]=i;
        }
    }
    for(int j=0; j<(1<<m); j++) {
        if(j&map[i])
            continue;
        if(j&(j<<1))
            continue;
        if(j&(j<<2))
            continue;
        dp[0][j][0]=num[j];
    }
    for(int j=1; j<=states; j++) {
        for(int k=1; k<=states; k++) {
            if(s[j]&s[k])
                continue;
            if(s[j]&map[2])
                continue;
            dp[2][j][k]=max(dp[2][j][k],dp[1][0][j]+num[j]);
        }
    }
    for(int i=3; i<=n; ++i)
        for(int j=1; j<=states; j++) {
            if(map[i]&s[j])
                continue;
            for(int k=1; k<=states; ++k) {
                if(s[k]&s[j])
                    continue;
                for(int w=1; w<=states; w++) {
                    if(((s[w]&s[k])==0)&&((s[w]&s[j])==0))
                        dp[i][k][j]=max(dp[i][k][j],dp[i-1][w][k]+num[j]);
                }
            }
        }
    for(int i=1; i<=states; ++i)
        for(int j=1; j<=states; ++j)
            ans=max(dp[n][i][j],ans);
    printf("%d",ans);
    return 0;
}

by DreamShadow @ 2018-08-25 11:29:06

I am P @[雪绮晶](/space/show?uid=110460) 

by ousuimei_68 @ 2018-08-25 11:29:11

@雪绮晶 要考虑上下两行吧。。。


by 雪绮晶 @ 2018-08-25 11:30:22

@ousuimei_68 …………我忘了…………谢谢


by AThousandSuns @ 2018-08-25 11:33:36

Please contact [email protected]!

(逃


by AThousandSuns @ 2018-08-25 11:35:02

打错了(尴尬)


上一页 |