头像

leon_ltox




离线:2个月前


最近来访(24)
用户头像
su尔
用户头像
卡路西法
用户头像
一路秒杀
用户头像
忘打周赛
用户头像
minc
用户头像
给个研究生上吧
用户头像
柠檬味的猪已黑化
用户头像
acefeng
用户头像
垂緌
用户头像
awesomegordon
用户头像
danielliu
用户头像
刃下心
用户头像
没有你哪有我
用户头像
ray_69
用户头像
Binarysearch
用户头像
Zxx
用户头像
初夏雾雨
用户头像
mwh_7
用户头像
@简单
用户头像
lyxose

活动打卡代码 AcWing 899. 编辑距离

leon_ltox
5个月前
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cmath>

using namespace std;

const int N = 15, M = 1010;

int n, m;
char str[M][N];
int f[N][N];

int edit_distance(char a[], char b[])
{
    int la = strlen(a + 1), lb = strlen(b + 1);
    for (int i = 0; i <= la; i ++ ) f[i][0] = i;
    for (int i = 0; i <= lb; i ++ ) f[0][i] = i;

    for (int i = 1; i <= la; i ++ )
        for (int j = 1; j <= lb; j ++ )
        {
            f[i][j] = min(f[i - 1][j] + 1, f[i][j - 1] + 1);
            f[i][j] = min(f[i][j], f[i - 1][j - 1] + (a[i] != b[j]));
        }

    return f[la][lb];
}

int main()
{
    cin >> n >> m;
    for (int i = 1; i <= n; i ++ ) cin >> str[i] + 1;

    while ( m -- )
    {
        char s[N];
        int limit;

        cin >> s + 1 >> limit;

        int res = 0;
        for (int i = 1; i <= n; i ++ ) 
            if (edit_distance(str[i], s) <= limit)
                res ++;
        cout << res << endl; 
    }

    return 0;
}
亮哦~


活动打卡代码 AcWing 902. 最短编辑距离

leon_ltox
5个月前
#include<bits/stdc++.h>
using namespace std;
const int INF = 2e9;
const int N = 2333;
int lena,lenb,f[N][N];
char a[N],b[N];

int main() {
    scanf("%d%s",&lena,a+1);
    scanf("%d%s",&lenb,b+1);
    for(register int i=1; i<=lena; i++) 
        for(register int j=1; j<=lenb; j++) 
            f[i][j] = INF;

    for(register int i=1; i<=lena; i++) f[i][0] = i;
    for(register int i=1; i<=lenb; i++) f[0][i] = i;

    for(register int i=1; i<=lena; i++) {
        for(register int j=1; j<=lenb; j++) {
           if (a[i] == b[j]) f[i][j] = f[i - 1][j -1];
           else
           {
               if (i < j) f[i][j] = f[i][j - 1] + 1;
               else if (i == j) f[i][j] = f[i - 1][j - 1] + 1;
               else f[i][j] = f[i - 1][j] + 1;
           }
        }
    }
    printf("%d\n",f[lena][lenb]);
    return 0;
}



leon_ltox
5个月前
#include <iostream>
#include <cstring>
#include <algorithm>

using namespace std;

const int N = 1010;
int n, m;
char a[N], b[N];
int f[N][N];

int main()
{
    cin >> n >> m >> a + 1 >> b + 1;

    for (int i = 1; i <= n; i ++ )
        for (int j = 1; j <= m; j ++ )
        {
            f[i][j] = max(f[i][j - 1], f[i - 1][j]);
            if (a[i]  == b[j]) f[i][j] = f[i - 1][j - 1] + 1;
        }

    cout << f[n][m] << endl;
    return 0;
}



leon_ltox
5个月前
#include <iostream>
#include <cstring>
#include <algorithm>

using namespace std;

const int N = 100010;

int n;
int a[N];
int q[N];

int main()
{
    cin >> n;
    for (int i = 0; i < n; i ++ ) cin >> a[i];

    int len = 0;
    for (int i = 0; i < n; i ++ )
    {
        int l = 0, r = len;

        while (l < r)
        {
            int mid = l + r + 1 >> 1;
            if (q[mid] < a[i]) l = mid;
            else r = mid - 1;
        }
        len = max(len, r + 1);
        q[r + 1] = a[i];
    }

    cout << len << endl;

    return 0;
}



leon_ltox
5个月前
#include <iostream>
#include <cstring>
#include <algorithm>

using namespace std;

const int N = 1010;
int n;
int a[N], f[N];
int main()
{
    cin >> n;

    for (int  i = 1; i <= n; i ++ ) cin >> a[i];

    int res = 1;
    for (int i = 1; i <= n; i ++ )
    {
        f[i] = 1;
        for (int j = 1; j < i; j ++ )
        {
            if (a[j] < a[i]) f[i] = max(f[i], f[j] + 1);
        }
        res = max(res, f[i]);
    }

    cout << res << endl;

    return 0;
}


活动打卡代码 AcWing 898. 数字三角形

leon_ltox
5个月前
#include <iostream>
#include <cstring>
#include <algorithm>

using namespace std;

const int N = 510;
int n;
int a[N][N], f[N][N];

int main()
{
    cin >> n;

    for (int i = 1; i <= n; i ++ )
        for (int j = 1; j <= i; j ++ )
            cin >> a[i][j];

    memset(f, -0x3f, sizeof f);

    f[1][1] = a[1][1];

    for (int i = 2; i <= n; i ++ )
    {
        for (int j = 1; j <= i; j ++ )
            f[i][j] = max(f[i - 1][j - 1] + a[i][j], f[i - 1][j] + a[i][j]);
    }

    int res = -0x3f3f3f3f;

    for (int i = 1; i <= n; i ++ ) res = max(res, f[n][i]);

    cout << res << endl;

    return 0;
}


活动打卡代码 AcWing 9. 分组背包问题

leon_ltox
5个月前
#include <iostream>
#include <cstring>
#include <algorithm>

using namespace std;

const int N  = 110;

int n, m, s;

int f[N], v[N], w[N];

int main()
{
    cin >> n >> m;

    for (int i = 0; i < n; i ++ ) 
    {
        cin >> s;
        for (int j = 0; j < s; j ++ ) cin >> v[j] >> w[j];
        for (int j = m; j >= 0; j -- )
        {
            for (int k = 0; k < s; k ++)
            {
                if (j >= v[k])
                {
                    f[j] = max(f[j], f[j - v[k]] + w[k]);
                }
            }
        }
    }

    cout << f[m] << endl;
    return 0;
}


新鲜事 原文

leon_ltox
5个月前
AcWing《Django框架课》拼团优惠!https://www.acwing.com/activity/content/introduction/72/group_buy/48507/


活动打卡代码 AcWing 5. 多重背包问题 II

leon_ltox
5个月前
#include <iostream>
#include <cstring>
#include <algorithm>

using namespace std;

const int N = 2010;
int f[N], n, m;
struct good
{
    int w, v;
};

int main()
{
    cin >> n >> m;
    vector<good> Goods;

    for (int i = 1; i <= n; i ++ )
    {
        int v, w, s;
        cin >> v >> w >> s;
        for (int k = 1; k <= s; k ++ )
        {
            s -= k;
            Goods.push_back({k*w, k*v});
        }
        if (s > 0) Goods.push_back({s * w, s * v});
    }

    for (auto t : Goods)
    {
        for (int j = m; j >= t.v; j -- )
        {
            f[j] = max(f[j], f[j - t.v] + t.w);
        }
    }

    cout << f[m] << endl;

    return 0;
}


活动打卡代码 AcWing 4. 多重背包问题

leon_ltox
5个月前
#include <iostream>
#include <cstring>
#include <algorithm>

using namespace std;

const int N = 110;

int n, m;
int v, w, s;
int f[N];

int main()
{
    cin >> n >> m;

    for (int i = 1; i <= n ;i ++ )
    {
        cin >> v >> w >> s;

        for (int j = m; j >= 0; j -- )
        {
            for (int k = 1; k <= s && k * v <= j; k ++ )
            {
                f[j] = max(f[j], f[j - k*v] + k * w);
            }
        }
    }

    cout << f[m];
    return 0;
}