Solution to a problem P2327 [SCOI2005] Minesweeper
Universal set of water problemsVery suitable for beginners to practice search
Look problem solutions are used in a variety of deities simple way, I LaijiangjiangviolenceSearch practice ....
For me I think that sprout new approach easier for you to understand search
To define the state of the first search, we define dfs (x, p) when x bit is p, there will be a state
Then we discuss the first case x + 1 bitsOnly two casesThen there will be a transfer
Secondly, when x is n, if true, then ++ ans, so with the boundary conditions
Finally, copy and paste the code you got 100 points and found that it's a bit like dynamic programming
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
#define ll long long
#define N 100005
int a[N], b[N], n;//a是左边那排,b是每一个格子是否放雷
ll ans;
void dfs(int x, int p) //第x个格子放 p个雷
{
b[x] = p;
if (x == n) //边界
{
if (b[x] + b[x - 1] == a[x]) //第n个格子放 p个雷 成立
ans++;
return;
}
for (int i = 0; i <= 1; i++) //讨论第x + 1个格子放不放雷
if (b[x] + b[x - 1] + i == a[x] && b[x] + i <= a[x + 1])
dfs(x + 1, i); //转移(滑稽
b[x] = 0;
}
int main()
{
cin >> n;
for (int i = 1; i <= n; i++)
cin >> a[i];
dfs(1, 1);
dfs(1, 0);
cout << ans;
return 0;
}
19.08.18