题目
思路
应该是经典铺瓷砖问题了,QAQ。
从左到右,从上到下去遍历这个H*W的网格,每遇到一个1x1的格子:
- 如果可以放1x1的瓷砖,就放1个1x1的瓷砖
- 如果可以水平放置1个2x1的瓷砖,就水平放1个2x1的瓷砖
- 如果可以竖直放置1个2x1的瓷砖,就竖直放1个2x1的瓷砖
可以用二进制(一个int类型的数)或者二维数组来标记每个格子的状态:有没有铺瓷砖。通过dfs来求解答案。
代码
二进制标记状态法:
#include <iostream>
#include <stdlib.h>
#include <stdio.h>
#include <algorithm>
#include <math.h>
#include <vector>
#include <map>
#include <queue>
#include <limits.h>
#include <stack>
using namespace std;
typedef long long ll;
const int maxn = 110;
int H, W, A, B, ans = 0;
void solve(int s, int bit, int a, int b)
{
if(s==H*W)
{
ans++;
return ;
}
if(bit&(1<<s))