本文共 1419 字,大约阅读时间需要 4 分钟。
题目:Old Macdonald wants to build a new hen house for his hens. He buys a new rectangular area of size N by M. The night before he builds the hen house, snake Rana devises an evil plan to plant bombs in K distinct cells in the area to kill the hens and eat them for dinner later.
The morning of, Old Macdonald notices that each of the K cells, where snake Rana planted a bomb, have a marking on them. That won’t stop him though, all he must do is build the hen house in an area with no bombs.
Assume that rows are numbered from top to bottom, and columns are numbered from left to right. Old Macdonald now wants to know the number of ways he can choose sub-rectangles of top left coordinates (x1, y1) and bottom right coordinates (x2, y2) (x1 ≤ x2) (y1 ≤ y2) such that there are no bombs in the sub rectangle.
有一个大的矩形区域,其中一些地方中有炸弹,现在问你有多少中矩阵的取法,使得任何一个矩阵里面都不包含炸弹。
思路:这个题是一个计数问题,我们可以使用容斥的方法去做,首先求出能构成矩阵的所有方案,相当于是在(n+1)条边中取两条边,在(m+1)条边中取两条边,得到总的方案数(n+1)*n/2*(m+1)*m/2,然后在减去包含奇数个炸弹的方案数,这时会多减掉一些部分,所以我们要在加上包含偶数个炸弹的方案数,想求包含几个炸弹,由于总炸弹的数量比较少,所以我们使用二进制的方式来判断包含的炸弹数。
#includeusing namespace std;const int maxn=1e4;const long long inf=1e9;struct Node{ long long x,y;} node[maxn];int main(){ int T; cin>>T; while(T--) { long long n,m,k; cin>>n>>m>>k; for(int i=0; i >node[i].x>>node[i].y; } long long ans=(long long)(n+1)*n/2*(m+1)*m/2;// cout< <
转载地址:http://ubgsi.baihongyu.com/