打印一个n*m矩阵,最大为7*7,每个矩阵a[i,j]>=a[i-1,j],并且a[i,j]>=a[i,j-1];
暴力搜索就行,但要一行一行搜索
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <vector>
#include <map>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <list>
using namespace std;
typedef long long ll;
int a[10][10];
int s[10][10];
int n,m,ans;
int ok(int x,int y){
if(x<1 || y<1) return 0;
return a[x][y];
}
void dfs(int x,int y){
if(x == n+1){//搜索完了
ans++;
return;
}
if(ok(x-1,y)<=0&&ok(x,y-1)<=0){
a[x][y] = 0;
if(y==m) dfs(x+1,1);//一行完了
else dfs(x,y+1);
}
if(ok(x-1,y)<=1&&ok(x,y-1)<=1){
a[x][y] = 1;
if(y==m) dfs(x+1,1);
else dfs(x,y+1);
}
if(ok(x-1,y)<=2&&ok(x,y-1)<=2){
a[x][y] = 2;
if(y==m) dfs(x+1,1);
else dfs(x,y+1);
}
a[x][y] = ans;
}
int main()
{
int i,j;
for(i = 1;i<=7;i++)
for(j = 1;j <= 7;j++){
ans = 0;
n = i,m = j;
dfs(1,1);
s[i][j] = ans;
}
int t;
scanf("%d",&t);
while(t--){
scanf("%d%d",&n,&m);
printf("%d\n",s[n][m]);
}
return 0;
}