Problem Description:
Today Czy found three sister, has a collection of hobbies he wants to find three places to hide the girls, will be an empty space abstracted into a row C column of the table, Czy to select 3 cells. However, the following two conditions are met:
(1) Any two cells are not in the same row.
(2) Any two cells are not in the same column.
The selection lattice exists a cost, while this cost is three lattice 22 between Manhattan distance and (e.g. (X1,Y1) and (X,y2) the Manhattan Distance for |x1-x2|+|y1-y2|). What the dog wants to know is how many programs it spends between mint and maxt.
Answer modulus 1000000007. The so-called two different scenarios are: As long as the selected cell has a different, it is considered a different scenario.
Input format:
One line, 4 integers, R, C, MinT, Maxt. 3≤r,c≤4000, 1≤mint≤maxt≤20000.
For 30% of data, 3≤r, c≤70.
Output format:
An integer that represents the result of the number of different selection scenarios after modulo 1000000007.
Input/Output Sample:
3 3 1 20000 3 3 4 7 4 6 9 7 5 4000 4000 4000 14000
6 0 264) 1212 859690013
Exercises
It is easy to find out that for three points (X1,y1) (X2,y2) (x3,y3), if any interchange coordinate costs are not changed, So test instructions becomes an enumeration of 3 horizontal and 3 ordinate, reasonable number of schemes
For x1,x2,x3, Y1,y2,y3, if there is x1<x2<x3, Y1<y2<y3, then the cost of the program is 2 (x3-x1) +2 (y3-y1).
Therefore, may wish to make x1<x2<x3, Y1<y2<y3, then by the permutation combination is easy to get, the final plan number multiply 6 namely is the answer.
and ( x1,y1) and (x3,y3) Form a rectangle, for a definite rectangular border, it's cost is certain, that 2 (x3-x1) +2 (y3-y1), which is the edge length of the rectangle. Its contribution to the answer is also certain, namely (x3-x1-1) * (y3-y1-1). The number of times the rectangle appears in the large rectangle of the r*c is also given, the rectangle is set to X and the width is Y, then (r-x+1) * (c-y+1) occurs. Then directly enumerate the length of the rectangle, and then you can figure out the answer.
Time Complexity of O (n^2)
1#include <iostream>2#include <cstdlib>3#include <cstdio>4#include <cmath>5#include <cstring>6#include <algorithm>7 #definell Long Long8 using namespacestd;9 intN,m,minn,maxx,ans;Ten intta[10005],tb[10005]; One intMain () A { - inti,j; -scanf"%d%d%d%d",&n,&m,&minn,&Maxx); the for(i=1; i<=n;i++) ta[i]= (n-i) * (I-1); - for(i=1; i<=m;i++) tb[i]= (m-i) * (I-1); - for(i=1; i<=n;i++) - for(j=1; j<=m;j++) + if(2* (I+J) >=minn&&2* (I+J) <=maxx) ans= (ans+ (LL) ta[i]*tb[j]*6%1000000007)%1000000007; -printf"%d", ans); + return 0; A}
View Code
"Noip simulator" Tibetan Girls ' place