The contest

Description

  殷犇有很多队员。他们都认为自己是最强的,于是,一场比赛开始了~

  于是安叔主办了一场比赛,比赛有n个题目,每个题目都有一个价值Pi和相对能力消耗Wi,但是有些题目因为太坑不能同时做出来,并且坑题具有传递性。(a和b一起做会坑、b和c会坑则a和c也会坑) ACM队员们想知道,于是他们想知道在能力范围内,它们最多可以作出多少价值的题目。

  聪明的你,告诉我,能帮帮他们吗?

Input

  第1行两个整数,n,Wmax,k(0<=n,Wmax,k<=1000),其中n为题目总数,Wmax为初始的总能力数.

  接下来n行,为每个题目的Pi,Wi(0<=Pi<=1000,1<=Wi<=10,均为整数)

  再接下来k行,每行2个数字a,b表示a和b会坑

Output

  对每组数据输出1行为最大可能价值

Sample Input

3 10 1
100 1
200 5
10 5
1 2

Sample Output

210

题意:做题目,给出一个初始能量值,n道题目。给出每道题目的价值和消耗,不会做的题目会传递影响。如果a,b不能同时做,b,c不能同时做
那么a,c也不能同时做。求最大价值
题解:并查集+分组背包

#include<stdio.h>

#include<iostream>

#include<string.h>

#include<set>

#include<vector>

using namespace std;

int father[1005];

int pri[1005];

int cost[1005];

int flag[1005];

int sum[1005];

 

int n,v,kk;

int max(int a,int b)

{

return a>b?a:b;

}

void init()

{

int i;

for(i=1;i<=n;i++) father[i]=i;

}

int finder(int x)

{

if(father[x]==x) return x;

else return father[x]=finder(father[x]);

}

void unioner(int x,int y)

{

int s1=finder(x);

int s2=finder(y);

if(s1==s2) return;

else father[s1]=s2;

}

int main()

{

int a,b,i,j,cnt,k;

set<int> s;

    vector<int> vm[1005];

while(scanf("%d %d %d",&n,&v,&kk)!=EOF)

{

s.clear();

for(i=1;i<=n;i++) vm[i].clear();

init();

for(i=1;i<=n;i++)

{

scanf("%d %d",&pri[i],&cost[i]);

}

        for(i=1;i<=kk;i++)

{

scanf("%d %d",&a,&b);

            unioner(a,b);

}

for(i=1;i<=n;i++)

{

           s.insert(finder(i));

}

        set<int>::iterator it;

int size=s.size();

cnt=0;

    for(it=s.begin();it!=s.end();it++)

{

int temp=*it;

cnt++;

for(j=1;j<=n;j++)

{

               if(temp==finder(j)) vm[cnt].push_back(j);

}

}

memset(sum,0,sizeof(sum));

for(k=1;k<=size;k++)

{

for(j=v;j>=0;j--)

{

for(i=0;i<vm[k].size();i++)

{

if(j>=cost[vm[k][i]])

{

sum[j]=max(sum[j],sum[j-cost[vm[k][i]]]+pri[vm[k][i]]);

}

}

}

}

printf("%d\n",sum[v]);

}

return 0;

}

 
  

 

转载于:https://www.cnblogs.com/ffhuguang/p/3354870.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Sure, I'd be happy to give you some ideas for organizing a speech contest. Here are some suggestions: 1. Determine the theme and rules: Decide on the theme of the contest and the rules for participants. Will it be an open topic, or will there be a specific theme? What is the maximum length of the speech? Will there be any specific guidelines for language or content? 2. Decide on the judging criteria: Determine how the speeches will be evaluated. Will judges be looking for content, delivery, or both? Will there be a score sheet or rubric that judges will use to score the speeches? 3. Recruit judges: Find people who are qualified to judge the speeches. Ideally, they should have experience in public speaking or have a background in the theme of the contest. 4. Promote the contest: Advertise the contest to potential participants, such as students, professionals, or members of a specific community. Use social media, flyers, and other methods to get the word out. 5. Registration and selection: Set a deadline for registration and selection of participants. Consider having a preliminary round to narrow down the field before the final competition. 6. Prepare the venue: Ensure that the venue is suitable for the contest. Make sure that there is adequate seating, sound equipment, and lighting for the speakers. 7. Hold the contest: Set a date and time for the contest, and make sure that all participants and judges are aware of the schedule. Encourage audience participation and provide refreshments. 8. Award ceremony: After the contest, hold an award ceremony to recognize the winners and participants. Provide certificates or other prizes to the top performers. I hope these ideas help you in organizing a successful speech contest!
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值