POJ1050【DP】
2024-09-05 22:03:38
题意:
求一个最大子矩阵和。
思路:
枚举行区间,然后求一个最大子序列和。
贴一发挫code…
#include <iostream>
#include <cstdio>
#include <string.h>
#include <algorithm>
using namespace std;
typedef __int64 LL;
const int N=1e2+10;
int a[N][N];
int dp[N];
int main()
{
int n;
scanf("%d",&n);
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
scanf("%d",&a[i][j]);
int ans;
ans=a[1][1];
for(int k=1;k<=n;k++)
{
for(int i=k;i<=n;i++)
{
for(int j=1;j<=n;j++)
{
if(i==k)
dp[j]=a[i][j];
else
dp[j]+=a[i][j];
}
int tmax=0;
for(int j=1;j<=n;j++)
{
if(tmax>0)
tmax+=dp[j];
else
tmax=dp[j];
if(tmax>ans)
ans=tmax;
}
}
}
printf("%d\n",ans);
return 0;
}
/*
4
0 -2 -7 0
9 2 -6 2
-4 1 -4 1
-1 8 0 -2
*/
最新文章
- Unity3D研究院之拓展系统自带组件的Inspector视图
- HDU 5876 关于补图的bfs
- 象写程序一样写博客:搭建基于github的博客
- Linux下c++中的atoi、atol、atoll、atof函数调用实例
- 【Log4j】 log4j.properties 使用
- bzoj2426
- python数据类型和3个重要函数
- 学习使用Vim(一)
- Java程序初始化的顺序
- php5.6在yum下安装redis
- 201521123016《Java程序设计》第10周学习总结
- Caused by: java.sql.BatchUpdateException: You have an error in your SQL syntax; check the manual tha
- (译文)开始学习Vue.js特性--Scoped Slots
- log4j配置及使用
- Python基础知识1-基础语法
- docker 安装mysql示例
- kali linux 入侵window实例
- [可能没有默认的字体]Warning: imagettfbbox() [function.imagettfbbox]: Invalid font filename...
- Maven安装及MyEclipse中使用Maven
- InnoDB: The log sequence number in ibdata files does not match