Title Link: http://acm.hdu.edu.cn/showproblem.php?pid=2639
Test instructions: Finding the K-Solution for 01 backpacks
DP (I, j) represents the I-optimal solution with a capacity of J
For the second-dimensional operation and the 01 backpack almost the same, but we only need to pay attention to each time to take the first k large.
1#include <algorithm>2#include <iostream>3#include <iomanip>4#include <cstring>5#include <climits>6#include <complex>7#include <fstream>8#include <cassert>9#include <cstdio>Ten#include <bitset> One#include <vector> A#include <deque> -#include <queue> -#include <stack> the#include <ctime> -#include <Set> -#include <map> -#include <cmath> + - using namespacestd; + A Const intMAXN =1010; at intN, M, K; - intV[MAXN], W[MAXN]; - intDP[MAXN][MAXN]; - intD[MAXN]; - - intMain () { inFreopen ("inch","R", stdin); - intT; toscanf"%d", &T); + while(t--) { -scanf"%d%d%d", &n, &m, &k); the for(inti =0; I < n; i++) { *scanf"%d", &v[i]); $ }Panax Notoginseng for(inti =0; I < n; i++) { -scanf"%d", &w[i]); the } +Memset (DP,0,sizeof(DP)); A for(inti =0; I < n; i++) { the for(intj = m; J >= W[i]; j--) { + intCNT =0; - for(intp =1; P <= k; p++) { $d[cnt++] =Dp[p][j]; $ if(J-w[i] >=0) { -d[cnt++] = Dp[p][j-w[i]] +V[i]; - } the } -Sort (d, d+cnt, greater<int>());WuyiCNT = unique (d, d+cnt)-D; the intQ =1; - for(intp =0; P < CNT; p++) { WuDP[Q++][J] =D[p]; - } About } $ } -printf"%d\n", Dp[k][m]); - } - return 0; A}
[HDOJ2639] Bone Collector II (k-gifted 01 backpack)