1060 [SCOI2009]粉刷匠 多维线性DP

分析

//-------------------------代码----------------------------

#define int ll
const int N = 80,M = 3000;
int n,m,t;
string in;
int sum[N][N];
int f[N][M][N];
int dp[N][M];
void solve()
{
     cin>>n>>m>>t;
    string s;
    fo(i,1,n) {
        cin>>s;
        s = ' ' + s;
        sum[i][0] = 0;
        for(int j = 1;j<=m;j++) {
            sum[i][j] = sum[i][j-1] + (s[j] == '1');
        }
       
    } 
    for(int i = 1;i<=n;i++) {
            for(int j = 1;j<=m;j++) {
                for(int k = 1;k<=m;k++) {
                    for(int l = j - 1;l < k;l ++ ) {
                        f[i][j][k] = max(f[i][j][k],f[i][j-1][l] + max(sum[i][k] - sum[i][l],k - l - sum[i][k] + sum[i][l]));
                    }
                }
            }
    }
    ll ans = 0;
        for(int i = 1;i<=n;i++) {
            for(int j = 1;j<=t;j++) {
                for(int k = 0;k <= min(j,m);k++) {
                    dp[i][j] = max(dp[i][j],dp[i-1][j-k] + f[i][k][m]);
                    ans = max(ans,dp[i][j]);
                }
            }
        }
    cout<<ans<<endl;
}

signed main(){
    clapping();TLE;
    
//    int t;cin>>t;while(t -- )
    solve();
//    {solve(); }
    return 0;
}

/*样例区


*/

//------------------------------------------------------------

 

posted @ 2022-07-23 11:54  er007  阅读(19)  评论(0编辑  收藏  举报