NBUT 1538 Submartix
来源:互联网 发布:再向虎山行gotv源码ts 编辑:程序博客网 时间:2024/06/06 02:44
[1538] K-Submartix
比较笨,写出了O(n^4),果断超时。看了队友的代码,优化到了O(n^3)。#include<cstdio>#define areaSum sum[ex][ey]-sum[ex][sy-1]-sum[sx-1][ey]+sum[sx-1][sy-1]const int N=252;int a[N][N],row[N][N],sum[N][N];//row第i行前j个和,sum前i行前j列和int main(){int n,m,key;while(~scanf("%d %d %d",&n,&m,&key)){for(int i=1;i<=n;i++)for(int j=1;j<=m;j++){scanf("%d",&a[i][j]);row[i][j]=row[i][j-1]+a[i][j];sum[i][j]=sum[i-1][j]+row[i][j];}int areaMin=1e9;for(int sx=1;sx<=n;sx++){for(int ex=sx;ex<=n;ex++){//横向一条for(int sy=1,ey=1;sy<=m;sy++){//推进查找int value=areaSum;while(value<key){ey++;if(ey>m) break;value=areaSum;}if(value<key) break;int area=(ex-sx+1)*(ey-sy+1);if(area<areaMin)areaMin=area;}}}if(areaMin==1e9)printf("-1\n");elseprintf("%d\n",areaMin);}return 0;}
0 0
- NBUT 1538 Submartix
- NOJ1538——[1538] K-Submartix
- NBUT
- NBUT
- NBUT
- NBUT
- NBUT
- 【NBUT
- NBUT
- NBUT
- NBUT
- NBUT
- NBUT
- nbut 1475
- NBUT 1481
- NBUT 1552
- NBUT 1477
- NBUT 1450
- 回不去了...
- User's Guide For Remind4Me
- Oracle 11g数据库相关操作
- 解决Sublime Text 3中文显示乱码问题
- do {...} while (0) 在宏定义中的作用
- NBUT 1538 Submartix
- 在潛移默化里··········
- MapReduce的Join
- python汉译英-调用Google翻译
- iOS Xcode工程目录的 folder 和 group的区别(蓝色和黄色文件夹的区别)
- nginx FastCGI模块(FastCGI)配置
- nginx反向代理服务器端口问题
- Xcode5的使用技巧和快捷键
- 嗖,2013-我早已出发