Codeforces A. Orchestra

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 ≤ r1 ≤ 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 }

 

 
posted @ 2016-02-29 23:42  sCjTyC  阅读(495)  评论(0编辑  收藏  举报