随笔 - 531  文章 - 0  评论 - 3  阅读 - 10215 
商店里有n朵云,云朵被编号为i12n

,并且每朵云都有一个价值。但一些云朵要搭配来买,  买一朵云则与这朵云有搭配的云都要买。

Joe的钱有限,希望买的价值最大

 

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include <iostream>
#include <queue>
#include <algorithm>
using namespace std;
 const int N= 1e5+5;
 int n,m,V,cost[N],val[N],fa[N];
 int f[N];
 int find(int x){
    if(x==fa[x]) return x;
    fa[x]=find(fa[x]);
    return fa[x];
 }
 void uni(int x,int y){
    int fx=find(x),fy=find(y);
    if(fx==fy) return ;
    fa[fx]=fy;
    cost[fy]+=cost[fx]; val[fy]+=val[fx];
 }
 signed main(){
    int i,j,x,y;
    cin>>n>>m>>V;
    for(i=1;i<=n;i++) cin>>cost[i]>>val[i];
    for(i=1;i<=n;i++) fa[i]=i;
    for(i=1;i<=m;i++) cin>>x>>y,uni(x,y);
     
     
    for(i=1;i<=n;i++)
     if(fa[i]==i){
        for(j=V;j>=cost[i];j--)
         f[j]=max(f[j],f[j-cost[i]]+val[i]);
    }
    cout<<f[V];
 }

 

posted on   towboat  阅读(11)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 展开说说关于C#中ORM框架的用法!
点击右上角即可分享
微信分享提示