2013南京 Onsite 代码(未提交)

将近1年没好好训练,结果弄个4题第一名,将近1半比赛的时间都没碰过pc^2 比赛的时候看的C,E,K, 都敲出来, 有机会交下, 我真是个逗逼, 
#include 
#include 
#include 

using namespace std;

const int maxr = 103;
const int maxc = 12;
int dp[103][12][2048+123][22];
char mp[maxr][maxc];
const int mod = 10e9+7;

int main(){
    freopen("c.in", "r", stdin);
    int N, M, C, D;
    while (~scanf("%d%d%d%d", &N, &M, &C, &D)){
        memset (dp, 0, sizeof(dp));
        for (int i=1; i<=N; ++i){
            scanf("%s", mp+i);
        }
        int lim = 1<<(M+1);/// 0 -> 
        dp[0][M][0][0] = 1;
        for (int i=1; i<=N; ++i){
            for (int k=0; (k<<1) 00  1*1 placed
                                dp[i][j][k][c+1] += dp[i][j-1][k][c];
                                dp[i][j][k][c+1] %= mod;
                            }
                            
                            for (int c=0; c<=D; ++c){/// 00 -> 01 or 10  non placed
                                dp[i][j][k|ma][c] += dp[i][j-1][k][c];
                                dp[i][j][k|ma][c] %= mod;
                                dp[i][j][k|mb][c] += dp[i][j-1][k][c];
                                dp[i][j][k|mb][c] %= mod;
                            }
                        }
                        if( (!(k&ma)) ^ (!(k&mb)) ) /// 01/10 -> 00 2*1 or 1*2 placed
                            for (int c=0; c<=D; ++c){
                                dp[i][j][k^(k&ma)^(k&mb)][c] += dp[i][j-1][k][c];
                                dp[i][j][k^(k&ma)^(k&mb)][c] %= mod;
                            }
                        /// 11 is invalid 
                    }
                    else {
                        if(!(k&ma) && !(k&mb)) /// 00 -> 00  forbid to place 
                            for (int c=0; c<=D; ++c){
                                dp[i][j][k][c] += dp[i][j-1][k][c];
                                dp[i][j][k][c] %= mod;
                            }
                    }
                }
            }
        }
        long long ans = 0;
        for (int i=C; i<=D; ++i){
            ans = (ans+dp[N][M][0][i])%mod;
        }
        printf("%lld\n", ans);
    }
    return 0;
}

你可能感兴趣的:(ACM周边,ACM,数据结构,ACM,动态规划)