[SCOI2005]扫雷

这道题一开始尝试用数学方程来解,后来觉得太复杂,事实上解的个数很少,所以就考虑搜索了,不确定的格子枚举,确定的格子填上,如果发现错误就退出。

 1 #include <iostream>
 2 #include <cstdio>
 3 #include <cstring>
 4 #include <algorithm>
 5 
 6 using namespace std;
 7 
 8 #define re register
 9 #define rep(i, a, b) for (re int i = a; i <= b; ++i)
10 #define repd(i, a, b) for (re int i = a; i >= b; --i)
11 #define maxx(a, b) a = max(a, b);
12 #define minn(a, b) a = min(a, b);
13 #define LL long long
14 #define inf (1 << 30)
15 
16 inline int read() {
17     int w = 0, f = 1; char c = getchar();
18     while (!isdigit(c)) f = c == '-' ? -1 : f, c = getchar();
19     while (isdigit(c)) w = (w << 3) + (w << 1) + (c ^ '0'), c = getchar();
20     return w * f;
21 }
22 
23 const int maxn = 1e4 + 5;
24 
25 int n, a[maxn], b[maxn], ans = 0;
26 
27 void dfs(int x) {
28     if (x == n+1 && a[x-1] == b[x-2] + b[x-1]) {
29         ans++;
30         return;
31     }
32     if (x > 1) {
33         if (a[x-1] == b[x-1] + b[x-2]) {
34             b[x] = 0;
35             dfs(x+1);
36         }
37         else if (a[x-1] == b[x-1] + b[x-2] + 1) {
38             b[x] = 1;
39             dfs(x+1);
40         }
41         else return;
42     } else {
43         b[x] = 0;
44         dfs(x+1);
45         b[x] = 1;
46         dfs(x+1);
47     }
48 }
49 
50 int main() {
51     n = read();
52 
53     rep(i, 1, n) a[i] = read();
54 
55     dfs(1);
56 
57     printf("%d", ans);
58 
59     return 0;
60 }

 

转载于:https://www.cnblogs.com/ac-evil/p/10316374.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值