/* -*- coding: utf-8 -*- * * 1703.cc: No.1703 Much Matching - yukicoder */ #include #include using namespace std; /* constant */ const int MAX_N = 1000; const int MAX_M = 1000; /* typedef */ /* global variables */ bool ts[MAX_N][MAX_M]; int dp[MAX_N + 1][MAX_M + 1]; /* subroutines */ inline void setmax(int &a, int b) { if (a < b) a = b; } /* main */ int main() { int n, m, q; scanf("%d%d%d", &n, &m, &q); for (int i = 0; i < q; i++) { int ai, bi; scanf("%d%d", &ai, &bi); ai--, bi--; ts[ai][bi] = true; } for (int i = 0; i <= n; i++) for (int j = 0; j <= m; j++) { if (i < n && j < m && ts[i][j]) setmax(dp[i + 1][j + 1], dp[i][j] + 1); if (i < n) setmax(dp[i + 1][j], dp[i][j]); if (j < m) setmax(dp[i][j + 1], dp[i][j]); } printf("%d\n", dp[n][m]); return 0; }