有趣的数 dp

有趣的数 dp

题解

注意开long long 某则乘以2可能溢出

#include<iostream>
using namespace std;

const int p=1e9+7;

int f[1005][7];

int n;

int main()
{
    
    
	cin>>n;
   	for(int i=1;i<=n;i++)
   	{
    
    
   		f[i][0]=1;
   		f[i][1]=(f[i-1][0]+f[i-1][1])%p;
   		f[i][2]=(f[i-1][3]+f[i-1][2])%p;
   		f[i][3]=(f[i-1][0]+f[i-1][3]*2)%p;
   		f[i][4]=(f[i-1][1]+f[i-1][3]+f[i-1][4]*2)%p;
   		f[i][5]=(f[i-1][2]+f[i-1][4]+f[i-1][5]*2)%p;
   		
	}
	
	cout<<f[n][5];
   	
	
	
	
	return 0;
}

猜你喜欢

转载自blog.csdn.net/weixin_45448563/article/details/113828748