Vijos 1250 Bravest Robotic Group backpack + Check Set

Source: Internet
Author: User
Tags value of pi

P1250 's bravest robot.Background

Wind designs a lot of robots. But they all think they are the strongest, so a game begins ~

Describe

Robots want to know who is the bravest, so they race to carry some things.

They arrive at a warehouse with n items, each with a value of pi and a weight of WI, but some items explode with the explosion and are transitive. (A and B will explode, B and C will explode, and a and C will explode)
Robots don't want to lose the equipment they've been able to extort from wind, so they want to know how much value they can get within their capabilities.

Can you help them?

Format input Format

Each set of test data
1th Act n,wmax,k (0<=n,wmax,k<=1000)
Next n rows, for each item's PI,WI (0<=pi<=1000,1<=wi<=10, are integers)
The next K-line, 2 numbers per line, a, a, A and B will explode.

Output format

Output 1 rows for each set of data
For maximum possible value

Example 1 sample input 1[copy]
3 10 1100 1200 510 51 2
Sample output 1[Copy]
210
Limit

1s per test point

Idea: Use and check set grouping, group Backpack Board;

#include <cstdio>#include<string>#include<queue>#include<stack>#include<cstring>#include<vector>#include<list>#include<Set>#include<map>using namespacestd;#definell Long Long#defineESP 0.00000000001Const intn=1e3+Ten, m=1e6+Ten, inf=1e9+Ten, mod=1000000007;intV[n],w[n];intDp[n];intFather[n];intzu;intFlag[n];intM[n][n];intS[n];intMaxxintXinty) {    returnX>y?x:y;}intFINDFA (intx) {    returnx==father[x]?x:father[x]=Findfa (father[x]);}voidHeintUintv) {    intx=FINDFA (U); inty=Findfa (v); if(x!=y) {father[x]=y; }}voidInitt (intx) {zu=1;  for(intI=1; i<=x;i++)    {        intv=Findfa (i); if(flag[v]==0) Flag[v]=zu++; M[FLAG[V]][S[FLAG[V]]++]=i; }}intMain () {intx,y,z,i,t,j; scanf ("%d%d%d",&x,&y,&z);  for(i=0; i<=x;i++) Father[i]=i;  for(i=1; i<=x;i++) scanf ("%d%d",&v[i],&W[i]);  for(i=1; i<=z;i++)    {        intu,v; scanf ("%d%d",&u,&v);    He (U,V);    } Initt (x);  for(i=1; i<zu;i++)    {         for(t=y;t>=0; t--)        {             for(j=0; j<s[i];j++)            if(T>=w[m[i][j]]) Dp[t]=maxx (dp[t],dp[t-w[m[i][j]]]+V[m[i][j]]); }} printf ("%d\n", Dp[y]); return 0;}

Vijos 1250 Bravest Robotic Group backpack + Check Set

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.