http://hihocoder.com/problemset/problem/1043

动态转移方程 :for v=cost..V 

        f[v]=max(f[v],f[v-c[i]]+w[i]);

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;

int n,m;
int dp[210000]={0};
void CompletePack(int cost,int weight)
{
    for(int i=cost;i<=m;i++)
    {
        dp[i]=max(dp[i],dp[i-cost]+weight);
    }
}

int main()
{
    int a,b;
    scanf("%d%d",&n,&m);
    for(int i=0;i<n;i++)
    {
       scanf("%d%d",&a,&b);
       CompletePack(a,b);
    }
    printf("%d\n",dp[m]);
    return 0;
}

 

相关文章:

  • 2021-09-30
  • 2021-08-07
  • 2022-12-23
  • 2021-10-21
  • 2021-09-01
  • 2022-01-25
  • 2021-08-07
  • 2022-03-08
猜你喜欢
  • 2021-09-30
  • 2022-12-23
  • 2021-07-03
  • 2021-09-30
  • 2022-12-23
  • 2021-08-24
  • 2021-11-22
相关资源
相似解决方案