[笔试强训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;
}
相关推荐
学java的小菜鸟啊17 分钟前
第五章 网络编程 TCP/UDP/Socket
java·开发语言·网络·数据结构·网络协议·tcp/ip·udp
我爱吃福鼎肉片21 分钟前
【C++】——list
c++·vector·list
溪午闻璐36 分钟前
C++ 文件操作
开发语言·c++
菜鸟求带飞_1 小时前
算法打卡:第十一章 图论part01
java·数据结构·算法
浅念同学1 小时前
算法.图论-建图/拓扑排序及其拓展
算法·图论
Antonio9151 小时前
【CMake】使用CMake在Visual Studio内构建多文件夹工程
开发语言·c++·visual studio
是小Y啦1 小时前
leetcode 106.从中序与后续遍历序列构造二叉树
数据结构·算法·leetcode
LyaJpunov1 小时前
C++中move和forword的区别
开发语言·c++
程序猿练习生1 小时前
C++速通LeetCode中等第9题-合并区间
开发语言·c++·leetcode
liuyang-neu1 小时前
力扣 42.接雨水
java·算法·leetcode