Demo entry 6717457



Submitted by anonymous on Feb 24, 2018 at 17:29
Language: C++. Code size: 670 Bytes.

using namespace std;
#define MAXN 1000
#define MAXC 100000
int V[MAXN], W[MAXN];
int d[MAXN][MAXC];
int main(){	
freopen("", "r", stdin);//重定向输入流	
freopen("data.out", "w", stdout);//重定向输出流	
int n, C;	
while(scanf("%d %d", &n, &C) != EOF){		
      for(int i=0; i<n; i++)	
          scanf("%d %d", &V[i], &W[i]);
     for(int j=0; j<=C; j++) 
      for(int i=0; i<=n; i++){			
           for(int j=0; j<=C; j++){						
                if(i>0 && j>=V[i-1])	
                d[i][j] =max(d[i-1][j],d[i-1][j-V[i-1]]+W[i-1]);			
printf("%d\n", d[n][C]);//最终求解的最大价值	
return 0;}

This snippet took 0.00 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).