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

 

posted @ 2019-09-27 23:37  MXR_alone  阅读(160)  评论(0编辑  收藏  举报