美团校招笔试题

大富翁游戏(类似于变态跳青蛙问题)

#include 
using namespace std;
int main()
{
    int n, ans;
    cin>>n;
    if(n<0)
        return 0;
    ans=1;
    for(int i =1;i



找零钱,动态规划


#include 
#include 
using namespace std;

int a[]={1,5,10,20,50,100};
long long f[6][10001];
int main()
    {
    int n;
    cin>>n;
    memset(f,0,sizeof(f));
    for(int i=0;i<=n;i++)
        f[0][i]=1;
    for(int i=1;i<6;i++)
        {
        for(int j=1;j<=n;j++)
            {
            for (int k=0;k<=(j/a[i]);k++)
                f[i][j]+=f[i-1][j-k*a[i]];
        }
    }
    cout<


最长公共子序列问题:动态规划


#include
#include
#include
#include
using namespace std;
int main(){
    string s1, s2;
    while (getline(cin, s1), getline(cin, s2)){
        int l1 = s1.size();
        int l2 = s2.size();
        vector> dp(l1 + 1, vector(l2 + 1, 0));
        int result = 0;
        for (int i = 1; i <= l1; i++){
            for (int j = 1; j <= l2; j++){
                if (s1[i - 1] == s2[j - 1]){
                    dp[i][j] = dp[i - 1][j - 1] + 1;
                    result = max(dp[i][j], result);
                }
                else{
                    dp[i][j] = 0;
                }
            }
        }
        cout << result << endl;
    }
    return 0;
}



你可能感兴趣的:(美团校招笔试题)