$Vijos P1250$
背包?
跑完并查集 分组背包完事
#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 ;
}
随机推荐
- python3 http.server备忘
python3英文的 打印出来应该不错: https://docs.python.org/3/library/http.server.html#module-http.server python2.7 ...
- selenium的调用
selenium的调用 制作人:全心全意 selenium调用谷歌浏览器 chrome = webdriver.Chrome() //创建谷歌浏览器对象 url="http://www.ba ...
- JavaEE最新技术整理--新技术
JavaEE最新技术整理-----https://blog.csdn.net/qq_21683643/article/details/79747922
- BNUOJ 14381 Wavio Sequence
Wavio Sequence Time Limit: 3000ms Memory Limit: 131072KB This problem will be judged on UVA. Origina ...
- 写给对<meta content="IE=edge,chrome=1" http-equiv="X-UA-Compatible">迷惑不解的小伙伴
1.X-UA-Compatible X-UA-Compatible是自从IE8新加的一个设置,对于IE8以下的浏览器是不识别的. 通过在meta中设置X-UA-Compatible的值,可以指定网页的 ...
- [USACO07OCT]障碍路线Obstacle Course
题目描述 Consider an N x N (1 <= N <= 100) square field composed of 1 by 1 tiles. Some of these ti ...
- 【HDOJ3068】最长回文(manacher)
题意:求一个由小写字母组成的字符串中的最长回文长度 cas<=120 n<=110000 思路:试manacher板子 ..]of char; p:..]of longint; ch:an ...
- Ubuntu 16.04清楚Dash历史记录
1.[系统设置]->[安全和隐私]->[文件和应用]->[清除使用数据] 2.清楚播放记录 rm -v ~/.local/share/recently-used.xbel 3.清楚打 ...
- 21、Java并发性和多线程-Java中的锁
以下内容转自http://ifeve.com/locks/: 锁像synchronized同步块一样,是一种线程同步机制,但比Java中的synchronized同步块更复杂.因为锁(以及其它更高级的 ...
- PHP array_keys()
定义和用法 array_keys() 函数返回包含数组中所有键名的一个新数组. 如果提供了第二个参数,则只返回键值为该值的键名. 如果 strict 参数指定为 true,则 PHP 会使用全等比较 ...