poj3624_Charm Bracelet (01背包问题)

2015-07-20 17:49:15 · 作者: · 浏览: 3

01背包问题:推荐资料《背包问题九讲》

#include 
  
   
using namespace std;
int cost,ans,val,n,V,f[12890];
int maxm(int a,int b){
   if(a>b) return a;
   return b;
}
int main(){
    cin>>n>>V;
    for(int i=0;i
   
    >cost>>val; for(int v=V;v>=cost;v--){ f[v]=maxm(f[v],f[v-cost]+val); ans=f[v]>ans?f[v]:ans; } } cout<