版权声明:来自星空计算机团队(QQ群:134826825)——StarSky_STZG https://blog.csdn.net/weixin_43272781/article/details/86554432
http://murphyc.fun/contest/5/problem/D
easy version:https://blog.csdn.net/weixin_43272781/article/details/86548056
Description
LZDFDSMLL最近收到了一个批萨,这个批萨可以表示成n行m列的矩形,已知这个批萨上有k块被吃掉了。
LZDFDSMLL一定要吃一块完整的正方形的批萨,请问他有多少种不同的批萨可以吃。
不同批萨的定义:
两个正方形批萨只要左上角的点不一样, 或者正方形批萨的边长不一样就算不同。
Input
第一行两个正数n,m, k, 分别表示矩阵的行数、矩阵的列数、被吃掉的块数。
接下来有k行,每行有两个数x, y, 表示在x行y列的那块批萨被吃掉了。
(1 <= n, m <= 5000, k <= min(5000, n*m))
Output
一个整数表示LZDFDSMLL有多少种不同的正方形批萨可以吃。
Sample Input 1
3 3 0
Sample Output 1
14
Sample Input 2
3 3 1
2 2
Sample Output 2
8
C++版本一
题解:DP
/*
*@Author: STZG
*@Language: C++
*/
#include <bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<cstdlib>
#include<cstring>
#include<cstdio>
#include<string>
#include<vector>
#include<bitset>
#include<queue>
#include<deque>
#include<stack>
#include<cmath>
#include<list>
#include<map>
#include<set>
//#define DEBUG
#define RI register int
using namespace std;
typedef long long ll;
//typedef __int128 lll;
const int N=5000+10;
const int MOD=1e9+7;
const double PI = acos(-1.0);
const double EXP = 1E-8;
const int INF = 0x3f3f3f3f;
int t,n,m,k,q,x,y;
ll ans,cnt,flag,temp;
int a[N][N];
int l[N][N];
int c[N][N];
int dp[N][N];
char str;
int main()
{
#ifdef DEBUG
freopen("input.in", "r", stdin);
//freopen("output.out", "w", stdout);
#endif
scanf("%d%d%d",&n,&m,&k);
//scanf("%d",&t);
//while(t--){}
for(int i=1;i<=k;i++){
scanf("%d%d",&x,&y);
a[x][y]=1;
}
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
if(!a[i][j])
dp[i][j]=min(min(dp[i][j-1],dp[i-1][j]),dp[i-1][j-1])+1;
//cout<<dp[i][j]<<endl;
ans+=dp[i][j];
}
}
cout<<ans<<endl;
//cout << "Hello world!" << endl;
return 0;
}