hihoCoder week7 完全背包

完全背包

题目链接 https://hihocoder.com/contest/hiho7/problem/1

#include <bits/stdc++.h>
using namespace std;

const int N = 500 + 10;
int need[N], value[N];

int dp[100000+10];

int main ()
{
    int n,V;
    scanf("%d %d", &n, &V);
    for(int i=1;i<=n;i++) 
        scanf("%d %d", &need[i], &value[i]);
    for(int i=1;i<=n;i++) {
        for(int j=need[i]; j<=V; j++) {
            dp[j] = max(dp[j], dp[j-need[i]] +value[i]);
        }
    }
    cout << dp[V] <<endl;
    return 0;
}

 

posted @ 2018-11-17 21:19  Draymonder  阅读(108)  评论(0编辑  收藏  举报