蓝桥杯 激光样式(暴搜)


标题:激光样式

x星球的盛大节日为增加气氛,用30台机光器一字排开,向太空中打出光柱。
安装调试的时候才发现,不知什么原因,相邻的两台激光器不能同时打开!
国王很想知道,在目前这种bug存在的情况下,一共能打出多少种激光效果?

显然,如果只有3台机器,一共可以成5种样式,即:
全都关上(sorry, 此时无声胜有声,这也算一种)
开一台,共3种
开两台,只1种

30台就不好算了,国王只好请你帮忙了。

要求提交一个整数,表示30台激光器能形成的样式种数。

注意,只提交一个整数,不要填写任何多余的内容。

// #pragma GCC optimize(2)
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <cmath>
#include <string>
#include <vector>
#include <stack>
#include <map>
#include <sstream>
#include <cstring>
#include <set>
#include <cctype>
#include <bitset>
#define IO                       \
	ios::sync_with_stdio(false); \
	// cout.tie(0);
using namespace std;
// int dis[8][2] = {0, 1, 1, 0, 0, -1, -1, 0, 1, -1, 1, 1, -1, 1, -1, -1};
typedef unsigned long long ULL;
typedef long long LL;
typedef pair<int, int> P;
const int maxn = 2e5 + 10;
const int maxm = 2e5 + 10;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const int inf = 0x3f3f3f3f;
const LL mod = 1e9 + 7;
const double pi = acos(-1);
int dis[4][2] = {1, 0, 0, -1, 0, 1, -1, 0};
int m[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int a[50];
int ans=0;
int n;
void DFS(int i)
{
	if(i==n+1)
	{
		ans++;
		return ;
	}
	if(i==1)
	{
		a[i]=0;
		DFS(i+1);
		a[i]=1;
		DFS(i+1);
	}
	else
	{
		a[i]=0;
		DFS(i+1);
		if(a[i-1]==0)
		{
			a[i]=1;
			DFS(i+1);
			a[i]=0;
		}
	}
	return ;
}
int main()
{
//#ifdef WXY
//	freopen("in.txt", "r", stdin);
	 freopen("out.txt", "w", stdout);
//#endif
	IO;
	cin>>n;
	DFS(1);
	cout<<ans;
	return 0;
}


 

猜你喜欢

转载自blog.csdn.net/qq_44115065/article/details/109091566