Constanze's Machine

本文介绍了一种使用斐波那契数列解决特定字符串形态计数问题的方法,通过分析字符串中的字符,利用动态规划预计算斐波那契数列,并根据字符串中连续字符的出现情况,计算出所有可能的形态组合数量。

原题地址
思路:

  1. 因为字符串中不能有m,w的出现,所以有w,m的就全为零
  2. 连续写几个u,或者m,发现连续的字符串符合斐波那切数列
  3. 因为问的是最多有多少种“形态”,所以就是所有连续u,m的排列和之积
#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll mod =1000000007;
ll f[1000000];
void fi(){
    f[1]=1;f[2]=2;
    for(int i=3;i<=100000;i++){
        f[i]=f[i-1]+f[i-2];
        f[i]%=mod;
    }
}
char s[100000];
int main() {
   
    cin >>s;
    fi();
    //cout<<f[5]<<endl;
    ll sum=1,flagu=0,flagn=0,uu=0,nn=0;
    ll len = strlen(s);
    for(int i=0;i<len;i++){//cout<<"uu="<<f[uu]<<endl;cout<<"nn="<<f[nn]<<endl;cout<<"sum="<<sum<<endl;
        if(s[i]=='m'||s[i]=='w'){
             return cout<<0<<endl,0;
        }
        if(s[i]!='n'&&flagn) {sum*=f[nn];sum%=mod;nn=0;flagn=0;}
        if(s[i]!='u'&&flagu) {sum*=f[uu];sum%=mod;uu=0;flagu=0;}
        if(s[i]=='u'&&!flagu){
            flagu=1;
            uu++;
            continue;
        }
        if(flagu&&s[i]=='u') {uu++;continue;}
        //cout<<12346<<endl;

        if(s[i]=='n'&&!flagn){
            flagn=1;
            nn++;
            continue;
        }
        if(s[i]=='n'&&flagn) {nn++;continue;}
        //cout<<123<<endal;


    }
    sum%=mod;
    if(uu){
        sum*=f[uu];
    sum%=mod;
    }
    if(nn){sum*=f[nn];
    sum%=mod;}

    cout<<sum<<endl;
    return 0;
}

### NVM Configuration for Each Instance Separately Node Version Manager (NVM) is a tool designed to manage multiple active Node.js versions on a single machine. When configuring NVM for each instance separately, it is important to ensure that each instance has its own isolated environment and configuration. Below is a detailed explanation of how this can be achieved. #### Isolating NVM Instances To configure NVM for each instance separately, the following considerations should be made: - **Environment Variables**: Each instance should have its own set of environment variables such as `NVM_DIR`, which defines the directory where NVM will store its configurations and installed Node.js versions[^1]. - **Separate Installation Directories**: Ensure that each instance has its own installation directory by setting a unique `NVM_DIR` for each one. For example, you could use `/home/user1/.nvm` for one user and `/home/user2/.nvm` for another. ```bash export NVM_DIR="$HOME/.nvm-instance1" ``` This command sets the `NVM_DIR` for a specific instance. It must be executed in the context of each instance's shell session. #### Installing Node.js Versions When using NVM, installing Node.js versions for each instance requires specifying the correct `NVM_DIR`. This ensures that the installed versions are isolated from other instances. ```bash nvm install 16 ``` The above command installs Node.js version 16 for the current instance. Since the `NVM_DIR` is already set, this operation will only affect the current instance. #### Managing Multiple Configurations For managing multiple configurations, it is advisable to create separate shell scripts or profiles for each instance. These scripts can include the necessary environment variable settings and initialization commands for NVM. ```bash # Example script for instance1 export NVM_DIR="$HOME/.nvm-instance1" [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm nvm use 16 ``` Each instance can then be managed independently by sourcing the appropriate script. #### Verifying Configuration After setting up the configurations, verify that each instance is correctly configured by checking the active Node.js version. ```bash node -v ``` This command outputs the currently active Node.js version for the instance. If the configurations are correct, the output should match the version specified during installation. ### Code Example for Automating Instance Setup Below is an example script that automates the setup of NVM for multiple instances: ```bash #!/bin/bash INSTANCE_NAME=$1 NODE_VERSION=$2 # Set unique NVM_DIR for the instance export NVM_DIR="$HOME/.nvm-$INSTANCE_NAME" # Install NVM if not already present if [ ! -d "$NVM_DIR" ]; then curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.5/install.sh | bash fi # Load NVM [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # Install the specified Node.js version nvm install $NODE_VERSION nvm use $NODE_VERSION ``` Save this script as `setup_nvm_instance.sh` and execute it with the desired instance name and Node.js version as arguments. ###
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值