[笔试强训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;
}
相关推荐
白狐_7982 分钟前
408 数据结构|红黑树 vs AVL:高频考点、易错判断与可能出题方式
数据结构·算法
aqiu1111117 分钟前
【C++ 代码分析与重构】常见 DFS 逻辑错误解析与修正
c++·重构·深度优先
zuozong_8 分钟前
C++类与对象
开发语言·c++·算法
hansang_IR12 分钟前
【代码】分层最短路模板
c++·算法·最短路
暖焰核心13 分钟前
C++模板进阶——特化全解
javascript·c++·jquery
励志不掉头发的内向程序员17 分钟前
【LibreCAD 2D架构】从两个坐标到图形实体:RS_ActionDrawLine如何创建RS_Line
开发语言·c++·qt·学习·系统架构
啊阿狸不会拉杆20 分钟前
《计算机网络-自顶向下方法》5.2 路由选择算法 读书笔记
计算机网络·算法·路由
rannn_11126 分钟前
【力扣hot100】多维动态规划|62、64、5、1143、72
算法·leetcode·动态规划
j7~33 分钟前
【C++】C++的类型转换--详解
c++·static_cast·const_cast·rtti·c语言类型转换·c++强制类型转换
吴声子夜歌35 分钟前
ApacheCommons——commons-math3(科学计算与线性代数)(一)
java·线性代数·算法·apache