6
2025-09-24 17:35:33
发布于:浙江
1阅读
0回复
0点赞
#include<bits/stdc++.h>
using namespace std;
#define dn dp[i][j][k]
const int N=502;
int dp[N][N][302];
int main(){
ios::sync_with_stdio(false);
cin.tie(0);cout.tie(0);
int t;cin>>t;
while(t--){
int n,m,x;cin>>n>>m>>x;
memset(dp,0,sizeof(dp));
for(int i=1; i<=n; i++){
for(int j=1; j<=m; j++){
char a;cin>>a;
for(int k=0; k<=x; k++){
dn=max(dp[i-1][j][k],dp[i][j-1][k])+(a=='1');
if(a=='?' && k) dn=max(dn,max(dp[i-1][j][k-1],dp[i][j-1][k-1])+1);
}
}
}
int mx=0;
for(int k=0; k<=x; k++) mx=max(mx,dp[n][m][k]);
cout<<mx<<"\n";
}
return 0;
}
这里空空如也
有帮助,赞一个