每周总结14

本周主要做了很多算法题,其中最经典的便是完全背包问题

 

#include <iostream>

using namespace std;

const int N = 1010;

int main()
{

    int f[N] = { 0 };
    int V[N] = { 0 };
    int W[N] = { 0 };

    int n = 0;
    int v = 0;

    cin >> n >> v;
    for (int i = 1; i <= n; i++) {
        cin >> V[i] >> W[i];
    }


    for (int i = 1; i <= n; i++) {

        for (int j = V[i]; j <= v; j++) {
            f[j] = max(f[j], f[j - V[i]] + W[i]);
        }
    }

    int Max = 0;
    for (int i = 0; i <= v; i++) {
        
        Max = max(Max, f[i]);
    }
    

    cout << Max;
    
}

 

posted @ 2022-10-17 08:21  软工小蜗牛  阅读(44)  评论(0编辑  收藏  举报