#include #include #include #include #include #include #include #include #include #include using namespace std; int n; int a[105][105]; int dp[105][105]; int sum[105][105]; int main(){ while(scanf("%d",&n)!=EOF){ for(int i = 1;i <= n;i++){ for(int j = 1;j <= n;j++){ scanf("%d",&a[i][j]); } } memset(dp,0,sizeof(dp)); for(int j = 1;j <= n;j++){ //j列的和 for(int i = 1;i <= n;i++){ sum[j][i] = sum[j][i-1] + a[i][j]; } } for(int i = 1;i <= n;i++){ for(int j = i;j <= n;j++){ int right = 0; for(int k = 1;k <= n;k++){ if(right >= 0){ right += sum[k][j] - sum[k][i-1]; } else{ right = sum[k][j] - sum[k][i-1]; } dp[i][j] = max(dp[i][j],right); } } } int ans = -INT_MAX; for(int i = 1;i <= n;i++){ for(int j = i;j <= n;j++){ if(dp[i][j] > ans){ ans = dp[i][j]; } } } cout << ans << endl; } return 0; }
題目描述:用1*2 的矩形通過組合拼成大矩形,求拼成指
[cpp] /* * 程序的版
#include<iostream> u
題意:給你幾個字符串,找到一個字符串,使其到所有字符串
【原題】 1911: [Apio20