Description
给你一个高为n ,宽为m列的网格,计算出这个网格中有多少个矩形,下图为高为2,宽为4的网格.
Input
第一行输入一个t, 表示有t组数据,然后每行输入n,m,分别表示网格的高和宽 ( n < 100 , m < 100).
Output
每行输出网格中有多少个矩形.
Sample Input
2
1 2
2 4
Sample Output
3
30
题目思路:这里也是用到组合数,先只看横边的节点数(n),从n中选2个点的总方案数为n1,
再看纵边的节点数(m),从m中选2的点的总方案数为m1,然后长方形是由4个点构成的,所以个数直接是n1*m1.
代码:
1 #include<iostream> 2 using namespace std; 3 int main() 4 { 5 int t,n,m; 6 cin>>t; 7 while(t--) 8 { 9 cin>>n>>m; 10 cout<<(n+1)*n*m*(m+1)/4<<endl; 11 } 12 return 0; 13 }