蓝桥杯 进击的青蛙
蓝桥杯 进击的青蛙
注意其实dp 前三个点的判断。
#include<algorithm>
#include<cmath>
#include<cstring>
using namespace std;
typedef long long ll;
const int N =1e6+10;
ll n,m=0;
struct cmp{
bool operator()(const int&a,const int&b) const{
return a>b;
}
};
const int MOD = 1000000007;
ll a[N];
int main(){
cin >> n;
for(int i =1;i<=n;i++){
cin>>a[i];
}
a[1] == 0? a[1]=1:a[1]=0;
a[2] == 0? a[2] =a[1]+1:a[2]=0;
a[3] == 0? a[3] =a[1]+a[2]+1:a[3]=0;
for(int i =4;i<=n;i++){
if(a[i]) a[i]=0;
else
a[i]=((a[i-1]%MOD)+(a[i-2]%MOD)+(a[i-3]%MOD))%MOD;
}
//for(int i = 1;i<=n;i++)cout<<a[i]<<" ";
if(a[n]) cout<< a[n];
else cout<<"No Way!";
return 0;
}