[笔试强训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;
}
相关推荐
脱氧核糖核酸__1 分钟前
LeetCode热题100——48.旋转图像(题解+答案+要点)
c++·算法·leetcode
木井巳3 分钟前
【递归算法】字母大小写全排列
java·算法·leetcode·决策树·深度优先
宵时待雨4 分钟前
优选算法专题2:滑动窗口
数据结构·c++·笔记·算法
Mr_pyx6 分钟前
LeetCode HOT 100 —— 矩阵置零(多种解法详解)
算法·leetcode·矩阵
葫三生7 分钟前
《论三生原理》系列:文化自信、知识范式重构与科技自主创新的思想运动源头?
大数据·人工智能·科技·深度学习·算法·重构·transformer
我叫Ycg9 分钟前
C++ 中关于插入函数insert() 与 emplace() 的区别与使用建议
开发语言·c++
谭欣辰9 分钟前
区间动态规划精解
c++·动态规划
Q741_14710 分钟前
每日一题 力扣 3761. 镜像对之间最小绝对距离 哈希表 数组 C++ 题解
c++·算法·leetcode·哈希算法·散列表
John.Lewis11 分钟前
C++加餐课-哈希:扩展学习(2)布隆过滤器
c++·算法·哈希算法
网域小星球22 分钟前
C++ 从 0 入门(三)|类与对象基础(封装、构造 / 析构函数,面试必考)
开发语言·c++·面试·构造函数·析构函数