hdu大学生程序设计竞赛(2015’12)1006 01 Matrix
来源:互联网 发布:网络英语考试时间 编辑:程序博客网 时间:2024/06/06 00:35
01 Matrix
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Problem Description
It's really a simple problem.
Given a "01" matrix with size by n*n (the matrix size is n*n and only contain "0" or "1" in each grid), please count the number of "1" matrix with size by k*k (the matrix size is k*k and only contain "1" in each grid).
Given a "01" matrix with size by n*n (the matrix size is n*n and only contain "0" or "1" in each grid), please count the number of "1" matrix with size by k*k (the matrix size is k*k and only contain "1" in each grid).
Input
There is an integer T (0 < T <=50) in the first line, indicating the case number.
Each test case begins with two numbers n and m (0<n, m<=1000), specifying the size of matrix and the query number.
Then n lines follow and each line contains n chars ("0" or "1").
Then m lines follow, each lines contains a number k (0<k<=n).
Each test case begins with two numbers n and m (0<n, m<=1000), specifying the size of matrix and the query number.
Then n lines follow and each line contains n chars ("0" or "1").
Then m lines follow, each lines contains a number k (0<k<=n).
Output
For each query, output the number of "1" matrix with size by k*k.
Sample Input
22 20100123 3010111111122
Sample Output
10722
/*题解:如果从左上角向右下角,每个点对应最大矩形的边长是很难考虑清楚地所以可以从右下角想左上角进行转移(dp是从局部到整体的思想)Down[i][j]表示这个点的下方有多少个连续的'1'Right[i][j]表示这个点的右方有多少个连续的'1'dp[i][j]表示以这个点为左上方顶点的矩形边长最大为多少状态转移方程:如果这个点对应的s[i][j]为'0',那么所有的数组均为0相反,则Down[i][j]=Down[i+1][j]+1,Right[i][j]=Right[i][j+1],dp[i][j]讨论一下就可以了然后知道了所有点的dp[i][j],利用后缀和的便可以求出每个边长有多少个方案了*/#include <map>#include <set>#include <stack>#include <queue>#include <cmath>#include <ctime>#include <vector>#include <cstdio>#include <cctype>#include <cstring>#include <cstdlib>#include <iostream>#include <algorithm>using namespace std;#define INF 0x3f3f3f3f#define inf -0x3f3f3f3f#define lson l,m,rt<<1#define rson m+1,r,rt<<1|1#define mem0(a) memset(a,0,sizeof(a))#define mem1(a) memset(a,-1,sizeof(a))#define mem(a, b) memset(a, b, sizeof(a))typedef long long ll;char s[1102][1102];int Down[1102][1102],Right[1102][1102],dp[1102][1102];int C[1002];int main(){ int n,t,m; scanf("%d",&t); while(t--){ scanf("%d%d",&n,&m); for(int i=1;i<=n;i++) scanf("%s",s[i]+1); for(int i=1;i<=n+10;i++){ for(int j=1;j<=n+10;j++) dp[i][j]=0,Down[i][j]=0,Right[i][j]=0; C[i]=0; } for(int i=n;i>=1;i--) for(int j=n;j>=1;j--){ if(s[i][j]=='0'){ Down[i][j]=0; dp[i][j]=0; Right[i][j]=0; } else{ Right[i][j]=Right[i][j+1]+1; Down[i][j]=Down[i+1][j]+1; if(Right[i][j]>=dp[i+1][j+1]+1&&Down[i][j]>=dp[i+1][j+1]+1) dp[i][j]=dp[i+1][j+1]+1; else dp[i][j]=min(Down[i][j],Right[i][j]); C[dp[i][j]]++; } } for(int i=n;i>=1;i--) C[i]+=C[i+1]; while(m--){ int k; scanf("%d",&k); printf("%d\n",C[k]); } } return 0;}
0 0
- hdu大学生程序设计竞赛(2015’12)1006 01 Matrix
- HDU计算机学院大学生程序设计竞赛(2015’12)1006 01 Matrix
- 计算机学院大学生程序设计竞赛(2015’12)01 Matrix
- 计算机学院大学生程序设计竞赛(2015’12) 1006 01 Matrix(dp)
- hdu 计算机学院大学生程序设计竞赛(2015’11)质方数
- hdu 计算机学院大学生程序设计竞赛(2015’11)游乐场
- hdu--计算机学院大学生程序设计竞赛(2015’11)
- hdu-- 计算机学院大学生程序设计竞赛(2015’11)
- hdu-- 计算机学院大学生程序设计竞赛(2015’11)
- hdu-- 计算机学院大学生程序设计竞赛(2015’11)
- hdu-- 计算机学院大学生程序设计竞赛(2015’11)
- HDU-计算机学院大学生程序设计竞赛(2015’11)1006 逆袭指数(枚举)
- hdu 计算机学院大学生程序设计竞赛(2015’12)The Country List
- hdu 计算机学院大学生程序设计竞赛(2015’12)Happy Value(最大生成树)
- hdu 计算机学院大学生程序设计竞赛(2015’12)The Magic Tower
- HDU计算机学院大学生程序设计竞赛(2015’12)1008 Study Words
- HDU计算机学院大学生程序设计竞赛(2015’12)1007 Pick Game
- HDU计算机学院大学生程序设计竞赛(2015’12)1003 The collector’s puzzle
- 深入浅出Java类和对象的初始化
- c语言变量与常量
- 使用Spring MVC统一异常处理实战
- C#中timer类 在C#里关于定时器类就有3个
- 数据结构学习笔记——算法复杂性分析
- hdu大学生程序设计竞赛(2015’12)1006 01 Matrix
- Hdu 2099之解题报告
- set -e
- Makfile wildcard:扩展通配符, notdir:去除路径, patsubst:替换通配符
- pip安装使用官方的源无法安装问题解决
- Android studio使用百度SDK
- C++11网络编程
- Day02-转义、常变量、printf和scanf、命名、驼峰标志、注释
- orcfile 与 parpuet 的压缩测试