• 2017 ACM/ICPC Asia Regional Shenyang Online number number number


    题意:求n个斐波那契数列组合都无法得到的最小数字

    解法:

    1 我们先暴力的求出前面几个数字

    2 然后再暴力的求递推

    3 接着矩阵快速幂(没写错吧?)

    /*#include<bits/stdc++.h>
    using namespace std;
    long long x[50];
    map<long long,int>Mp;
    void dfs(int pos,long long sum,int cnt,int n){
        if(cnt==n){
            Mp[sum]=1;
            return;
        }
        if(cnt>n){
            return;
        }
        for(int i=pos;i<=20;i++){
            dfs(i+1,sum+x[i],cnt+1,n);
        }
    }
    int main(){
        x[0]=0;
        x[1]=1;
        for(int i=2;i<=21;i++){
            x[i]=x[i-1]+x[i-2];
        }
        for(int i=0;i<=21;i++){
            Mp[x[i]]=1;
        }
        //dfs(0,0,0,3);
        for(int i=2;i<=5;i++){
    
            dfs(0,0,0,i);
            for(long long j=0;j<=x[21];j++){
                if(Mp[j]==0){
                    cout<<j<<endl;
                    break;
                }
            }
        }
        return 0;
    }*/
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    #include <iostream>
    #include <algorithm>
    #define mset(a,i) memset(a,i,sizeof(a))
    using namespace std;
    typedef long long ll;
    const int mod=998244353;
    struct Mal{
        ll x[4][4];
    };
    Mal mul(Mal a,Mal b){
        Mal c;
        memset(c.x,0,sizeof(c.x));
        for(int i=0;i<3;i++){
            for(int j=0;j<3;j++){
                for(int k=0;k<3;k++){
                    c.x[i][j]+=((a.x[i][k]+mod)*(b.x[k][j]+mod))%mod;
                    c.x[i][j]%=mod;
                }
            }
        }
        return c;
    }
    Mal Qp(int n){
        Mal a,b;
        memset(a.x,0,sizeof(a.x));
        memset(b.x,0,sizeof(b.x));
        a.x[0][0]=3;
        a.x[0][1]=-1;
        a.x[0][2]=1;
        a.x[1][0]=1;
        a.x[2][2]=1;
        for(int i=0;i<3;i++){
            b.x[i][i]=1;
        }
        while(n){
            if(n&1){
                b=mul(b,a);
            }
            a=mul(a,a);
            n/=2;
        }
        return b;
    }
    ll k;
    int main(){
        while(~scanf("%lld",&k)){
            if(k==1){
                cout<<"4"<<endl;
                continue;
            }
            if(k==2){
                cout<<"12"<<endl;
                continue;
            }
            Mal pos,X;
            pos.x[0][0]=12;
            pos.x[1][0]=4;
            pos.x[2][0]=1;
            X=mul(Qp(k-2),pos);
            ll ans=X.x[0][0]%mod;
            printf("%lld
    ",ans);
        }
        return 0;
    }
    /*
    1 2 3 4 5 6 7 8 9 10 11 12
    4
    12
    33
    88
    232
    609
    1596
    4180
    10945
    28656
    75024
    196417
    99999999
    702476551
    9999999
    395293026
    */
  • 相关阅读:
    关于iframe页面里的重定向问题
    iframe跨域解决方案
    sql 查询优化小计
    年轻不能遇见太惊艳的人
    图片上传预览
    脚本
    前端常见跨域解决方案
    react
    react高阶组件
    React + MobX 状态管理入门及实例
  • 原文地址:https://www.cnblogs.com/yinghualuowu/p/7550437.html
Copyright © 2020-2023  润新知