标签:
Description
Input
Output
Sample Input
Sample Output
#include<stdio.h> #include<stdlib.h> int DP(int w[],int v[],int N,int M) { int f[1024]={0}; for( int i=1; i<=N; i++ ) { for( int j=M; j>=0; j-- ) { if( j>=v[i]&&f[ j ]<f[j-v[i]]+w[i] ) f[ j ]= f[ j-v[i] ] + w[i]; } } return f[M]; } int main() { int n,N,M; int v[1005],w[1005]; scanf( "%d",&n ); for( int i=0; i<n; i++ ) { scanf( "%d%d",&N,&M ); for( int j=1; j<=N; j++ ) scanf( "%d",&w[j] ); for( int k=1; k<=N; k++ ) scanf( "%d",&v[k] ); printf( "%d\n",DP( w , v, N ,M ) ); } return 0; }
标签:
原文地址:http://www.cnblogs.com/xinxiangqing/p/4725543.html