当前位置: 首页> 健康> 美食 > 网站分站加盟_javaweb网上商城源码_百度竞价开户费用_北京网站seo公司

网站分站加盟_javaweb网上商城源码_百度竞价开户费用_北京网站seo公司

时间:2025/7/11 6:02:19来源:https://blog.csdn.net/m0_73596392/article/details/147066633 浏览次数:0次
网站分站加盟_javaweb网上商城源码_百度竞价开户费用_北京网站seo公司

应该用dp做的但是我太懒懒得看题解了 留到考试的时候看

超时20分代码:

#include<bits/stdc++.h>
using namespace std;
int N, M, L, K;
struct Edge {int to, length;Edge(int to, int length) :to(to), length(length) {}
};
vector<int> color;//颜色标签
vector<vector<Edge>> graph;//邻接表
//vector<int> path;
int max_length = 0;//最大长度
//i:当前遍历节点
//colors:目前找到的颜色集合
//num:结点个数
void dfs(int i,set<int> colors,int num,int now_length) {if (num > L) {return;}else {//说明找到了if (i == N - 1) {/*for (int i = 0; i < path.size(); i++)cout << path[i] << " ";cout << endl;*/max_length = max(max_length, now_length);return;}//没找到继续遍历else {for (Edge e : graph[i]) {int to = e.to;int length = e.length;int col = color[to];//说明当前颜色不存在if (colors.find(col) == colors.end()) {//path.push_back(to);colors.insert(col);dfs(to, colors, num + 1, now_length + length);colors.erase(col);//path.pop_back();}}}}}
//找到最长观光路线:
//颜色各不相同 结点数小于等于L
//越长越好
void solve() {set<int> c;c.insert(color[0]);dfs(0, c, 1, 0);cout << max_length;
}
int main() {//N:结点个数(0~N-1)//M:边的个数//L:理想观光路线节点上限//K:颜色种类(0~K-1)cin >> N >> M >> L >> K;cin.ignore();color.resize(N);for (int i = 0; i < N; i++) {cin>>color[i];}//重置图的大小graph.resize(N);vector<int> U(M), V(M), D(M);for (int i = 0; i < M; i++) {cin>>U[i];}for (int i = 0; i < M; i++) {cin >> V[i];}for (int i = 0; i < M; i++) {cin >> D[i];}//构建图for (int i = 0; i < M; i++) {Edge e = Edge(V[i], D[i]);graph[U[i]].push_back(e);}solve();return 0;
}

关键字:网站分站加盟_javaweb网上商城源码_百度竞价开户费用_北京网站seo公司

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

责任编辑: