zoukankan      html  css  js  c++  java
  • noip模拟 分割土地(dp)

    懒得搬题面QAQ

    #include<cstdio>
    #include<cstring>
    using namespace std;
    const int mod=1e8+7;
    const int N=1010;
    int f[N][N<<1][2];
    int main()
    {
        freopen("field.in","r",stdin);
        freopen("field.out","w",stdout);
        int n,k;
        scanf("%d %d",&n,&k);
        f[1][1][0]=1;
        f[1][2][1]=1;
        for(int i=2;i<=n;i++)
            for(int j=1;j<=k;j++)
                f[i][j][0]=(f[i-1][j][1]*2+f[i-1][j-1][0]+f[i-1][j-1][1]+f[i-1][j][0])%mod,
                f[i][j][1]=(f[i-1][j-1][0]*2+f[i-1][j-1][1]*2+f[i-1][j-2][0]+f[i-1][j-2][1]+f[i-1][j][1])%mod;
        printf("%d
    ",(f[n][k][0]+f[n][k][1])%mod);
        fclose(stdin);
        fclose(stdout);
        return 0;
    }
    View Code

    题解:
    DP。
    F[i,j,k]表示前i行分配了j块栏栅然后最后一行的状态是k的方案数。k为1时两列的栏栅不同,k为2时两列位于同个栏栅。
    转移看Code或手推

  • 相关阅读:
    asp.net web生命周期
    图的数据结构1
    最长公共子串
    内部排序

    棋盘覆盖问题
    队列
    矩阵连乘问题
    图的数据结构2
    旅行售货员问题
  • 原文地址:https://www.cnblogs.com/12fs/p/7482132.html
Copyright © 2011-2022 走看看