$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 ;
}
随机推荐
- plot3d
plot3d plot3D a format for structured grid data that was popularized by NASA's CFD visualization Aut ...
- BZOJ 5028 小Z的加油店
[题解] 本题要求求出区间内的各个元素通过加减之后能够得出的最小的数,那么根据裴蜀定理可知答案就是区间内各个元素的最大公约数. 那么本题题意化简成了维护一个序列,支持区间加上某个数以及查询区间元素的最 ...
- Quadtrees(四分树)
uva 297 Quadtrees Time Limit: 3000MS Memory Limit: Unknown 64bit IO Format: %lld & %llu Subm ...
- [K/3Cloud] K/3 Cloud1.0怎样和2.0共存在一台服务器上
第一步:安装Cloud1.0,创建管理中心,创建业务数据中心,备份管理数据库和业务数据库,并且备份安装目录: 第二步:卸载Cloud1.0,清理安装目录,安装Cloud2.0,创建管理中心,创建业务数 ...
- codevs 1296 营业额统计 (splay 点操作)
题目大意 每次加入一个值,并且询问之前加入的数中与该数相差最小的值. 答案输出所有相差值的总和. 解题分析 = = 参考程序 #include <bits/stdc++.h> using ...
- python中实现将普通字典dict转换为java中的treeMap
上代码: from heapq import heappush,heappop from collections import OrderedDict def toTreeMap(paramMap): ...
- some notes about ADDM and AWR
Use the sophisticated management and monitoring features of the Oracle DatabaseDiagnostic and Tuning ...
- 【Storage】IBM DS8100开机及配置过程
************************************************************************ ****原文:blog.csdn.net/cla ...
- SecureCRT 8.0公布
百度搜索到的7.3 注冊码生成器还是能够用于8.0的破解. 破解时,选择手动输入(Enter Licence Manually)产生的代码. 添加了一些特性,我最看重的是: 1. 能够在以下命令窗体 ...
- iOS中的成员变量,实例变量,属性变量
在ios第一版中: 我们为输出口同时声明了属性和底层实例变量,那时,属性是oc语言的一个新的机制,并且要求你必须声明与之对应的实例变量,例如: 注意:(这个是以前的用法) @interface MyV ...