背包?

跑完并查集 分组背包完事

#include <bits/stdc++.h>
#define rep(i,j,n) for(register int i=j;i<=n;i++)
#define Rep(i,j,n) for(register int i=j;i>=n;i--)
#define low(x) x&(-x)
using namespace std ;
typedef long long LL ;
const int inf = INT_MAX >> 1 ;
inline LL In() { LL res(0) , f(1) ; register char c ;
#define gc c = getchar()
while(isspace(gc)) ; c == '-' ? f = - 1 , gc : 0 ;
while(res = (res << 1) + (res << 3) + (c & 15) , isdigit(gc)) ;
return res * f ;
#undef gc
} int n , m , k ;
const int N = 1000 + 5 ;
int p[N] , w[N] ;
int fa[N] ;
int cnt[N] ;
int V[N][N] ;
int W[N][N] ;
int dp[N] ; inline int find(int x) {
return fa[x] == x ? fa[x] : fa[x] =find(fa[x]) ;
}
inline void merge(int x,int y) {
fa[find(x)] = find(y) ;
} inline void Ot() {
memset(V,0,sizeof(V)) ;
memset(W,0,sizeof(W)) ;
n = In() , m = In() , k = In() ;
rep(i,1,n) fa[i] = i ;
rep(i,1,n) p[i] = In() , w[i] = In() ;
rep(u,1,k) merge(In() , In()) ;
rep(i,1,n) {
int q = find(i) ;
V[q][++cnt[q]] = p[i] ;
W[q][cnt[q]] = w[i] ;
}
rep(i,1,n) Rep(j,m,0) rep(u,1,cnt[i])
W[i][u] <= j ? dp[j] = max(dp[j] , dp[j-W[i][u]]+V[i][u]) : 0 ;
cout << dp[m] << endl ;
}
signed main() {
return Ot() , 0 ;
}

随机推荐

  1. 第十五节:Web爬虫之selenium动态渲染爬取

    selenium是一个用于Web应用程序测试的工具.Selenium测试直接运行在浏览器中,就像真正的用户在操作一样.支持的浏览器包括IE(7, 8, 9, 10, 11),Mozilla Firef ...

  2. Discuz 部署,500 – 内部服务器错误。 您查找的资源存在问题,因而无法显示。

    Windows7 IIS 500 – 内部服务器错误解决方案 1.解决方法:打开IIS,在功能视图中找到“错误页”,双击进去后,看最右边的“操作”下的“编辑功能设置…”,将“错误响应”下的“详细错误” ...

  3. [luoguP1433] 吃奶酪(DP || Dfs)

    传送门 深搜加剪纸可A(O(玄学) 1274ms) ——代码 #include <cmath> #include <cstdio> #include <iostream& ...

  4. noip模拟赛 天天和不可描述

    分析:直接就这么翻肯定是不行的,换一种想法:有括号就是把括号里的字符串倒着输出,如果在括号里又遇到了括号就继续倒着输出,相当于递归. 我们可以用递归直接做,也可以用一层循环搞定,每次从左括号跳到右括号 ...

  5. codevs3410 别墅房间

    题目描述 Description 小浣熊松松到他的朋友家别墅去玩,发现他朋友的家非常大,而且布局很奇怪.具体来说,朋友家的别墅可以被看做一个N*M的矩形,有墙壁的地方被标记为’#’,其他地方被标记为’ ...

  6. - > 强烈推荐!!!

    学长的微博总是能帮我们解决很多问题QAQ,超有用的: http://blog.csdn.net/cax1165/article/category/6294316/6

  7. Hadoop2.0之YARN

    YARN(Yet Another Resource Negotiator)是Hadoop2.0集群中负责资源管理和调度以及监控运行在它上面的各种应用,是hadoop2.0中的核心,它类似于一个分布式操 ...

  8. 1. FrogRiverOne 一苇渡江 Find the earliest time when a frog can jump to the other side of a river.

    package com.code; public class Test04_3 { public static int solution(int X, int[] A) { int size = A. ...

  9. CUDA编程(二) CUDA初始化与核函数

    CUDA编程(二) CUDA初始化与核函数 CUDA初始化 在上一次中已经说过了,CUDA成功安装之后,新建一个project还是十分简单的,直接在新建项目的时候选择NVIDIA CUDA项目就能够了 ...

  10. Python3标准库(一) 内置函数

    Python中内置了很多的函数,而学习标准库我们需要事先熟悉这些内置函数,所以在这里一个个进行介绍.有些函数比较简单,只给予文字描述,而有些函数会给出示例代码帮助理解. 1.abs(x):返回一个整数 ...