跳到正文

Wrong_Dimension

1113931

负负得正

在洛谷打开
资料、奖项与版本

资料

编号
1113931
抓取

陶片放逐

+ 进入主站
− 进入主站
无权限变更

查看记录

???

放烟花

C++
#include <bits/stdc++.h>
using namespace std;

int main() {
    
    return 0;
}
C++
#include <bits/stdc++.h>
using namespace std;

struct Item {
    string name;
    int value;
    Item(string n, int v) : name(n), value(v) {}
};
bool cmp(const Item& a, const Item& b) {
    return a.name.size() > b.name.size();
}
void parse_item_line(string& line, string& name, int& value) {
    string clean_line;
    for (char c : line) {
        if (c != ' ') clean_line += c;
    }
    size_t colon_pos = clean_line.find(':');
    if (colon_pos != string::npos) {
        name = clean_line.substr(0, colon_pos);
        value = stoi(clean_line.substr(colon_pos + 1));
    }
}
int main() {
    int N;
    cin >> N;
    cin.ignore();
    string s;
    getline(cin, s);
    int len_s = s.size();
    vector<Item> items;
    for (int i = 0; i < N; ++i) {
        string line, name;
        int value;
        getline(cin, line);
        parse_item_line(line, name, value);
        items.emplace_back(name, value);
    }
    sort(items.begin(), items.end(), cmp);
    vector<int> dp(len_s + 1, 0);
    for (int i = 1; i <= len_s; ++i) {
        dp[i] = dp[i - 1];
        for (const Item& item : items) {
            int len_item = item.name.size();
            if (len_item > i) continue;
            string sub = s.substr(i - len_item, len_item);
            if (sub == item.name) {
                dp[i] = max(dp[i], dp[i - len_item] + item.value);
            }
        }
    }
    cout << dp[len_s] << endl;
    return 0;
}
代码
▒███████▒ ██░ ██  ▄▄▄       ███▄    █   ▄████▓██   ██▓ ▒█████   ███▄    █   ▄████ ▒███████▒ ██░ ██ ▓█████  ███▄    █     ██▓  ██████    ▓█████▄   ██████  ▄▄▄▄   
▒ ▒ ▒ ▄▀░▓██░ ██▒▒████▄     ██ ▀█   █  ██▒ ▀█▒▒██  ██▒▒██▒  ██▒ ██ ▀█   █  ██▒ ▀█▒▒ ▒ ▒ ▄▀░▓██░ ██▒▓█   ▀  ██ ▀█   █    ▓██▒▒██    ▒    ▒██▀ ██▌▒██    ▒ ▓█████▄ 
░ ▒ ▄▀▒░ ▒██▀▀██░▒██  ▀█▄  ▓██  ▀█ ██▒▒██░▄▄▄░ ▒██ ██░▒██░  ██▒▓██  ▀█ ██▒▒██░▄▄▄░░ ▒ ▄▀▒░ ▒██▀▀██░▒███   ▓██  ▀█ ██▒   ▒██▒░ ▓██▄      ░██   █▌░ ▓██▄   ▒██▒ ▄██
  ▄▀▒   ░░▓█ ░██ ░██▄▄▄▄██ ▓██▒  ▐▌██▒░▓█  ██▓ ░ ▐██▓░▒██   ██░▓██▒  ▐▌██▒░▓█  ██▓  ▄▀▒   ░░▓█ ░██ ▒▓█  ▄ ▓██▒  ▐▌██▒   ░██░  ▒   ██▒   ░▓█▄   ▌  ▒   ██▒▒██░█▀  
▒███████▒░▓█▒░██▓ ▓█   ▓██▒▒██░   ▓██░░▒▓███▀▒ ░ ██▒▓░░ ████▓▒░▒██░   ▓██░░▒▓███▀▒▒███████▒░▓█▒░██▓░▒████▒▒██░   ▓██░   ░██░▒██████▒▒   ░▒████▓ ▒██████▒▒░▓█  ▀█▓
░▒▒ ▓░▒░▒ ▒ ░░▒░▒ ▒▒   ▓▒█░░ ▒░   ▒ ▒  ░▒   ▒   ██▒▒▒ ░ ▒░▒░▒░ ░ ▒░   ▒ ▒  ░▒   ▒ ░▒▒ ▓░▒░▒ ▒ ░░▒░▒░░ ▒░ ░░ ▒░   ▒ ▒    ░▓  ▒ ▒▓▒ ▒ ░    ▒▒▓  ▒ ▒ ▒▓▒ ▒ ░░▒▓███▀▒
░░▒ ▒ ░ ▒ ▒ ░▒░ ░  ▒   ▒▒ ░░ ░░   ░ ▒░  ░   ░ ▓██ ░▒░   ░ ▒ ▒░ ░ ░░   ░ ▒░  ░   ░ ░░▒ ▒ ░ ▒ ▒ ░▒░ ░ ░ ░  ░░ ░░   ░ ▒░    ▒ ░░ ░▒  ░ ░    ░ ▒  ▒ ░ ░▒  ░ ░▒░▒   ░ 
░ ░ ░ ░ ░ ░  ░░ ░  ░   ▒      ░   ░ ░ ░ ░   ░ ▒ ▒ ░░  ░ ░ ░ ▒     ░   ░ ░ ░ ░   ░ ░ ░ ░ ░ ░ ░  ░░ ░   ░      ░   ░ ░     ▒ ░░  ░  ░      ░ ░  ░ ░  ░  ░   ░    ░ 
  ░ ░     ░  ░  ░      ░  ░         ░       ░ ░ ░         ░ ░           ░       ░   ░ ░     ░  ░  ░   ░  ░         ░     ░        ░        ░          ░   ░      
░                                             ░ ░                                 ░                                                      ░                     ░ 

还没有收录这位用户的文章。