心情好一点又滚回去刷题
来自hzwer博客
http://218.5.5.242:9018/JudgeOnline/problem.php?id=1289
在2行N(1<=N<=12000)列的矩阵中已知第一行的所有格子的信息,求第二行的可能方案数
解法值得学习
#include<iostream>
using namespace std;
int ans=0;
int n;
int a[12001];
bool b[12001];
bool pd(int x)
{
int s=b[x];
if(x==1)return 1;
if(x-1>=1)s+=b[x-1];
if(x-2>=1)s+=b[x-2];
if(a[x-1]==s)return 1;
else return 0;
}
void dfs(int x)
{
if(x==n+1&&pd(n+1))ans++;
if(pd(x))dfs(x+1);
b[x]=1;
if(pd(x))dfs(x+1);
b[x]=0;
}
int main()
{
cin>>n;
for(int i=1;i<=n;i++)
cin>>a[i];
dfs(1);
cout<<ans;
return 0;
}