• POJ1296


    #include<iostream>
    #include<cstring>
    #include<cstdio>
    #include<algorithm>
    #include<queue>
    #include<cmath>
    #include<vector>
    #define maxn 40005
    #define rint register int
    #define inf 0x3f3f3f3f
    #define pb push_back
    #define mod (int)1e9 + 7
    using namespace std;
    inline int read()
    {
        char c=getchar();int x=0,f=1;
        while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
        while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}
        return x*f;
    }
    inline void write(int x)
    {
        if(x<0) putchar('-'),x=-x;
        if(x>9) write(x/10);
        putchar(x%10+'0');
        return ;
    }
    
    int n, m, t, ans; 
    int a[55][55], dp[55][2505], f[55][55][2505], sum0[maxn], sum1[maxn], pre[2][55][55];
    //f[i][j][k]表示第i行到第j格用了k次最多染对数,dp[i][k]表示到第i行用了k次最多染对数 
    char c;
    
    inline int max(int a, int b) { return a > b ? a : b; } 
    
    signed main()
    {
        n = read(), m = read(), t = read();
        for (rint i = 1; i <= n; ++i)
            for (rint j = 1; j <= m; ++j)
            {
                scanf("%1d", &a[i][j]);
                pre[ a[i][j] ][i][j] =     pre[ a[i][j] ][i][j - 1] + 1;
                pre[ a[i][j] ^ 1 ][i][j] =     pre[ a[i][j] ^ 1 ][i][j - 1];
            } 
        for (rint i = 1; i <= n; ++i)
          for (rint j = 1; j <= m; ++j)
            for (rint k = 1; k <= m; ++k)
              for (rint l = 0; l < j; ++l)
              {
                  f[i][j][k] = max(f[i][j][k], f[i][l][k - 1] + pre[1][i][j] - pre[1][i][l]);
                  f[i][j][k] = max(f[i][j][k], f[i][l][k - 1] + pre[0][i][j] - pre[0][i][l]);
              }
        for (rint i = 1; i <= n; ++i)
          for (rint j = 1; j <= t; ++j)
            for (rint k = 0; k <= min(m, j); ++k)
              dp[i][j] = max(dp[i][j], dp[i - 1][j - k] + f[i][m][k]), ans = max(ans, dp[i][j]); 
        write(ans);
        return 0;
    } 
     
    View Code
  • 相关阅读:
    mybatis 控制台打印sql脚本
    删除git库中untracked files(未监控)的文件
    亚马逊云实例被攻击 一个月账单三百多美刀
    ubuntu下搜索文件
    django 富文本展示 以及 post提交出错
    亚马逊EC2弹性IP收费
    redis 相关命令
    使用XSHELL连接EC2虚拟机实例
    springMVC下集成active MQ发送邮件
    ubuntu下安装JDK并搭建activeMQ
  • 原文地址:https://www.cnblogs.com/mxrmxr/p/11601026.html
Copyright © 2020-2023  润新知