标签:des style blog http color io os java ar
3 5 10 2 1 2 3 4 5 5 4 3 2 1 5 10 12 1 2 3 4 5 5 4 3 2 1 5 10 16 1 2 3 4 5 5 4 3 2 1
12 2 0
1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <cmath> 5 #include <algorithm> 6 #include <climits> 7 #include <vector> 8 #include <queue> 9 #include <cstdlib> 10 #include <string> 11 #include <set> 12 #include <stack> 13 #define LL long long 14 #define pii pair<int,int> 15 #define INF 0x3f3f3f3f 16 using namespace std; 17 const int maxn = 1005; 18 int dp[maxn][75],v[maxn],c[maxn],tmp[maxn*10]; 19 int N,V,K; 20 int main() { 21 int t,cnt,z; 22 scanf("%d",&t); 23 while(t--){ 24 scanf("%d %d %d",&N,&V,&K); 25 for(int i = 1; i <= N; i++) 26 scanf("%d",v+i); 27 for(int i = 1; i <= N; i++) 28 scanf("%d",c+i); 29 memset(dp,0,sizeof(dp)); 30 for(int i = 1; i <= N; i++){ 31 for(int j = V; j >= c[i]; j--){ 32 cnt = 0; 33 for(int k = 1; k <= K; k++){ 34 tmp[cnt++] = dp[j][k]; 35 tmp[cnt++] = dp[j-c[i]][k]+v[i]; 36 } 37 sort(tmp,tmp+cnt); 38 z = 1; 39 for(int i = cnt-1; i >= 0; i--){ 40 if(z > K) break; 41 if(i == cnt-1 || tmp[i] != tmp[i+1]) 42 dp[j][z++] = tmp[i]; 43 } 44 } 45 } 46 printf("%d\n",dp[V][K]); 47 } 48 return 0; 49 }
标签:des style blog http color io os java ar
原文地址:http://www.cnblogs.com/crackpotisback/p/3970408.html