Find a regular problem, this kind of problem is more ingenious, to carefully observe and find the law
1. Assuming that there is only one row, there are n columns, then the number of rectangles consisting of a small rectangle is n, and the number of rectangles consisting of two small rectangles is n-1 .... The number of rectangles consisting of n small rectangles is 1, so the number of rectangles is
n + (n-1) + (n-2) + ... + 2 + 1 = n * (n + 1)/2
2. Similarly, suppose that there is only one column, the number of rectangles that can be formed is also n * (n + 1)/2
So, the total number of rectangles is the total number of rectangles that the row consists of the number of rectangles * columns
The code is as follows
1#include <stdio.h>2 3 intMain ()4 {5 intN, M, N;6scanf"%d", &N);7 while(n--)8 {9scanf"%d%d", &n, &m);Ten intt = n * (n +1) /2* M * (M +1) /2; Oneprintf"%d\n", T); A } - - return 0; the}
HDU-2524 Rectangle A + B