A. Orchestra

time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

Paul is at the orchestra. The string section is arranged in an r × c rectangular grid and is filled with violinists with the exception of nviolists. Paul really likes violas, so he would like to take a picture including at least k of them. Paul can take a picture of any axis-parallel rectangle in the orchestra. Count the number of possible pictures that Paul can take.

Two pictures are considered to be different if the coordinates of corresponding rectangles are different.

Input

The first line of input contains four space-separated integers rcnk (1 ≤ r, c, n ≤ 10, 1 ≤ k ≤ n) — the number of rows and columns of the string section, the total number of violas, and the minimum number of violas Paul would like in his photograph, respectively.

The next n lines each contain two integers xi and yi (1 ≤ xi ≤ r, 1 ≤ yi ≤ c): the position of the i-th viola. It is guaranteed that no location appears more than once in the input.

Output

Print a single integer — the number of photographs Paul can take which include at least k violas.

Examples
input
2 2 1 1
1 2
output
4
input
3 2 3 3
1 1
3 1
2 2
output
1
input
3 2 3 2
1 1
3 1
2 2
output
4
Note

We will use '*' to denote violinists and '#' to denote violists.

In the first sample, the orchestra looks as follows


*#
**

Paul can take a photograph of just the viola, the 1 × 2 column containing the viola, the 2 × 1 row containing the viola, or the entire string section, for 4 pictures total.

In the second sample, the orchestra looks as follows


#*
*#
#*

Paul must take a photograph of the entire section.

In the third sample, the orchestra looks the same as in the second sample.

思路:前缀数组和,然后暴力枚举两两点对,以上边的点为左上顶点下边的点为右下顶点,

as[x][y]-as[x][j-1]-(as[i-1][y]-as[i-1][j-1]);就为这个矩阵内的符合要求的点的个数,判断下是否这个矩阵成立即可复杂度n4;
 1 #include<stdio.h>
2 #include<algorithm>
3 #include<iostream>
4 #include<string.h>
5 #include<math.h>
6 #include<queue>
7 #include<map>
8 using namespace std;
9 typedef long long LL;
10 int ans[20][20]= {0};
11 int as[20][20];
12 int bs[20][20];
13 int main(void)
14 {
15 int i,j,k,p,q,n,m;
16 int x,y;
17 cin>>n>>m>>p>>q;
18 memset(ans,0,sizeof(ans));
19
20 for(i=0; i<p; i++)
21 {
22 cin>>x>>y;
23 ans[x][y]=1;
24 }
25 for(i=1; i<=n; i++)
26 {
27 for(j=1; j<=m; j++)
28 {
29 as[i][j]=ans[i][j]+as[i][j-1];
30 }
31 }
32 for(i=1; i<=m; i++)
33 {
34 for(j=1; j<=n; j++)
35 {
36 as[j][i]+=as[j-1][i];
37 }
38 }
39 int cnt=0;
40 for(i=1;i<=n;i++)
41 {
42 for(j=1;j<=m;j++)
43 {
44 for(x=i;x<=n;x++)
45 {
46 for(y=j;y<=m;y++)
47 {
48 int uu=as[x][y]-as[x][j-1]-(as[i-1][y]-as[i-1][j-1]);
49 if(uu>=q)
50 {
51 cnt++;
52 }
53 }
54 }
55 }
56 }
57 cout<<cnt<<endl;
58 return 0;
59 }
 

最新文章

  1. Javaweb——过滤器映射
  2. C#的yield关键字
  3. 查看oracle当前session
  4. Android开发之初识Camera图像采集
  5. SQL给字段加上统一的某个字符
  6. 利用no_merge优化
  7. Linux系统中如何添加自己的库文件路径
  8. redhat5安装phantomjs
  9. php 引用一点要小心使用
  10. ROS Indigo在ubuntu1404上的安装方法
  11. HashMap 深入分析
  12. SQL baseline_11g
  13. Ajax请求传递数组参数
  14. IP地址查询接口API
  15. placeholder的使用
  16. Spring点滴四:Spring Bean生命周期
  17. XAMPP启动mysql问题
  18. 启动secondarynamenode时报错
  19. 写shell脚本需要注意哪些地方----零基础必看
  20. 【原创】6. 在MYSQL++中实现SQL语法中的NULL

热门文章

  1. 计算机网络-4-7-内部网关协议OSPF
  2. UE4类型数据自动注册
  3. Yarn的Tool接口案例
  4. day16 Linux三剑客之awk
  5. 商业爬虫学习笔记day2
  6. pyqt5的下拉菜单,可以进行输入文字
  7. tomcat启动和停止脚本
  8. hadoop accesscontrolException
  9. Linux上Zookeeper集群搭建
  10. 【C/C++】C++ warning: control reaches end of non-void function return