## L2-052 吉利矩阵

题目链接：https://pintia.cn/problem-sets/994805046380707840/exam/problems/type/7?problemSetProblemId=1781658570803388427&page=1

题目分析：题目说了N是[2,4]之间的正整数，N只有三种取值，所以这道题也可以用暴力解法

其实只需要先遍历N*N方阵左上角的(N-1)*(N-1)方阵，再利用剩下的没有遍历的变量来验证方阵的正确性就行了，通俗易懂

```cpp
#include<bits/stdc++.h>
using namespace std;
int main(){
    int L,N;
    cin>>L>>N;
    int cnt=0;
    if(N==2){
        for(int a=0;a<=L;a++){
            int b=L-a;
            int c=L-a;
            int d=a;
            if(b>=0 && c>=0 && d>=0){
                cnt++;
            }
        }
    }
    else if(N==3){
    for (int a = 0; a <= L; a++){
        for (int b = 0; b <= L; b++){
            for (int c = 0; c <= L; c++){
                for (int d = 0; d <= L; d++){
                    int e = L - a - b;
                    int f = L - c - d;
                    int g = L - a - c;
                    int h = L - b - d;
                    int i = L - g - h;
        
                    if (e<0||f<0||g<0||h<0||i<0) continue;
                    if (e + f + i == L) cnt++;
                    }
                }
            }
        }
    }
    else if(N==4){
        for (int a=0;a<=L;a++)for(int b=0;b<=L;b++)for(int c=0;c<=L;c++)
        for (int d=0;d<=L;d++)for(int e=0;e<=L;e++)for(int f=0;f<=L;f++)
        for (int g=0;g<=L;g++)for(int h=0;h<=L;h++)for(int i=0;i<=L;i++)
        {
            int j = L-a-b-c;
            int k = L-d-e-f;
            int l = L-g-h-i;

            int m = L-a-d-g;
            int n = L-b-e-h;
            int o = L-c-f-i;

            int p = L-m-n-o;

            if (j<0||k<0||l<0||m<0||n<0||o<0||p<0) continue;
            if (j+k+l+p == L && m+n+o+p == L) cnt++;
        }
    }
    cout<<cnt<<endl;
    return 0;
}
