Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
可以让背包当前的重量作为状态。#include<stdio.h> struct bracelet { int w; int v; }; struct bracelet b[3410]; int dp[12990]; int n,m; void main() { int i,j; scanf("%d%d",&n,&m); for(i=1;i<=n;i++) { scanf("%d%d",&b[i].w,&b[i].v); } for(i=1;i<=n;i++) { for(j=0;j+b[i].w<=m;j++) { if(dp[j]<dp[j+b[i].w]+b[i].v) dp[j]=dp[j+b[i].w]+b[i].v; } } printf("%d",dp[0]); } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator