牛客 一战到底编程挑战

链接:https://ac.nowcoder.com/acm/challenge/terminal
来源:牛客网

题目描述

有一个长度为n的序列a,已知a[1]=a[n]=1,且对于2 <= x <= n,a[x] / a[x-1]是以下三个数字之一 [ 1,-2,0.5 ],问有多少种不同的序列满足题意。
两个序列不同当且仅当它们有至少一个位置上的数字不同,序列a可以为任何实数。

输入描述:

一个整数 表示n (1<= n <= 1e3)

输出描述:

一个整数 表示答案模10
9
+7
示例1

输入

复制
5

输出

复制
7
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
 
const int MAXN = 1e5+10;
const int INF = 0x3f3f3f3f;
const int N = 1010;
const int MOD = 1e9+7;
 
LL n;
LL ans = 0;
LL dp[N][N];
int main(){
    while(scanf("%lld",&n)!=EOF){
        ans = 0;
        memset(dp,0,sizeof(dp));
        for(int i=0;i<=n;i++){
            dp[i][0] = dp[i][i] = 1;
        }
        for(int i=1;i<=n;i++)
            for(int j=1;j<=n;j++)
                dp[i][j] = (dp[i-1][j-1] + dp[i-1][j]) % MOD;
        for(int i=0;i<=(n-1)/4;i++)
            ans = (ans + (dp[n-1][i*4] * dp[4*i][2*i]) % MOD) % MOD;
        cout<<ans<<endl;
    }
    return 0;
}

转载自:https://blog.csdn.net/l18339702017/article/details/80786058

原文地址:https://www.cnblogs.com/tp25959/p/10345861.html