[笔试强训day08]

文章目录

  • [HJ108 求最小公倍数](#HJ108 求最小公倍数)
  • [NC95 数组中的最长连续子序列](#NC95 数组中的最长连续子序列)
  • [DP39 字母收集](#DP39 字母收集)

HJ108 求最小公倍数

HJ108 求最小公倍数

cpp 复制代码
#include<iostream>

using namespace std;

int a,b;

int gcd(int a,int b)
{
    if(b==0) return a;
    return gcd(b,a%b);
}
int main()
{
    cin>>a>>b;
    int t=gcd(a,b);
    int ans=a*b/t;
    cout<<ans<<endl;
    return 0;
}

NC95 数组中的最长连续子序列

NC95 数组中的最长连续子序列

cpp 复制代码
class Solution {
public:

    int MLS(vector<int>& arr) {
        int n=arr.size();
        sort(arr.begin(),arr.end());
        int ans=0;
        for(int i=0;i<n;)
        {
            int j=i+1,cnt=1;
            while(j<n)
            {
                if(arr[j]-arr[j-1]==1)
                {
                    cnt++;
                    j++;
                }
                else if(arr[j]-arr[j-1]==0) j++;
                else break;
            }
            ans=max(cnt,ans);
            i=j;
        }
        return ans;
    }
};

DP39 字母收集

DP39 字母收集

cpp 复制代码
#include<iostream>

using namespace std;

const int N=505;
int m,n;
char g[N][N];
int dp[N][N];

int main()
{
    cin>>m>>n;
    for(int i=0;i<m;i++)
    {
        for(int j=0;j<n;j++)
        {
            cin>>g[i][j];
        }
    }

    for(int i=0;i<=m;i++)
    {
        for(int j=0;j<=n;j++)
        {
            int t=0;
            if(g[i][j]=='l') t=4;
            else if(g[i][j]=='o') t=3;
            else if(g[i][j]=='v') t=2;
            else if(g[i][j]=='e') t=1;

            dp[i][j]=max(dp[i][j-1],dp[i-1][j])+t;
        }
    }
    cout<<dp[m][n]<<endl;
    return 0;
}
相关推荐
Zevalin爱灰灰13 小时前
现代密码学 第二章——流密码【下】
算法·密码学
飞Link15 小时前
大模型长文本的“救命稻草”:深度解析 TurboQuant 与 KV Cache 压缩技术
算法
郝学胜-神的一滴16 小时前
深度学习优化核心:梯度下降与网络训练全解析
数据结构·人工智能·python·深度学习·算法·机器学习
Je1lyfish16 小时前
CMU15-445 (2025 Fall/2026 Spring) Project#3 - QueryExecution
linux·c语言·开发语言·数据结构·数据库·c++·算法
许彰午16 小时前
03-二叉树——从递归遍历到非递归实现
java·算法
Brilliantwxx16 小时前
【C++】 vector(代码实现+坑点讲解)
开发语言·c++·笔记·算法
叼烟扛炮17 小时前
C++第三讲:类和对象(中)
开发语言·c++·类和对象
KuaCpp17 小时前
C++新特性学习
c++·学习
墨染千千秋18 小时前
C/C++ Keywords
c语言·c++
ximu_polaris18 小时前
设计模式(C++)-行为型模式-中介者模式
c++·设计模式·中介者模式