zoukankan      html  css  js  c++  java
  • 【CYH-02】NOIp考砸后虐题赛:转换式:题解

    这道题真的不难吧。

    @AKEE@AKEE 大佬所说,此题的确可以将n推广到一般情况。

    但题面还是良心的只到了N<=4N<=4

    以目前的题目来看,简单模拟即可。

    分别弄N=1,2,3,4N=1,2,3,4的情况判断就行。

    下面奉上std

    代码:

    #include<bits/stdc++.h>
    #define L 1000001
    using namespace std;
    long long int a[100001],b,c,d,e,x=0,xx=2;
    long long int mo=10000029;
    int main() {
        int n,t,N;
        cin>>N;
        if(N==1) {
            cin>>n>>b;
            a[0]=1;
            for(int i=1; i<=n; i++) {
                a[i]=a[i-1]*b%mo;
            }
            if(a[n]>=0)cout<<a[n];
            else cout<<a[n]+mo;
            return 0;
        }
        if(N==2) {
            cin>>n>>b>>c;
            a[1]=b;
            a[2]=a[1]*a[1]-c*xx;
            a[2]%=mo;
            if(a[n]!=x) {
                cout<<a[n]<<endl;
            }
            for(int j=3; j<=n; j++) {
                if(a[j]!=x)continue;
                a[j]=a[j-1]*b-a[j-2]*c;
                a[j]%=mo;
            }
            if(a[n]>=0)cout<<a[n];
            else cout<<a[n]+mo;
            return 0;
        }
        if(N==3) {
            cin>>n>>b>>c>>d;
            a[0]=3;
            a[1]=b;
            a[2]=b*b-2*c;
            a[2]%=mo;
            for(int i=3; i<=n; i++) {
                a[i]=b*a[i-1]-c*a[i-2]+d*a[i-3];
                a[i]%=mo;
            }
            if(a[n]>=0)cout<<a[n];
            else cout<<a[n]+mo;
            return 0;
        }
        if(N==4) {
            cin>>n>>b>>c>>d>>e;
            a[0]=4;
            a[1]=b;
            a[2]=b*b-2*c;
            a[2]%=mo;
            a[3]=b*(a[2]-c)+3*d;
            a[3]%=mo;
            for(int i=4; i<=n; i++) {
                a[i]=b*a[i-1]-c*a[i-2]+d*a[i-3]-e*a[i-4];
                a[i]%=mo;
            }
            if(a[n]>=0)cout<<a[n];
            else cout<<a[n]+mo;
            return 0;
        }
        return 0;
    }
    
  • 相关阅读:
    附近地点搜索 ,地图
    网站访问量
    后台全选功能以及数据的提交方法
    首页banner特效
    等待加载提示
    缩略图轮播
    遍历input。select option 选中的值
    django1补充
    pythonweb框架django框架1
    图书馆管理系统的页面设计
  • 原文地址:https://www.cnblogs.com/ShineEternal/p/10834273.html
Copyright © 2011-2022 走看看