Vijos P1314 - NASA的食物计划 (二维背包)

代码

#include <cstdio>
#include <stack>
#include <set>
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <functional>
#include <cstring>
#include <algorithm>
#include <cctype>
#include <ctime>
#include <cstdlib>
#include <fstream>
#include <string>
#include <sstream>
#include <map>
#include <cmath>
#define LL long long
#define SZ(x) (int)x.size()
#define Lowbit(x) ((x) & (-x))
#define MP(a, b) make_pair(a, b)
#define MS(arr, num) memset(arr, num, sizeof(arr))
#define PB push_back
#define F first
#define S second
#define ROP freopen("input.txt", "r", stdin);
#define MID(a, b) (a + ((b - a) >> 1))
#define LC rt << 1, l, mid
#define RC rt << 1|1, mid + 1, r
#define LRT rt << 1
#define RRT rt << 1|1
#define BitCount(x) __builtin_popcount(x)
const double PI = acos(-1.0);
const int INF = 0x3f3f3f3f;
using namespace std;
const LL MAXN = 400 + 10;
const int MOD = 20071027;
 
typedef pair<int, int> pii;
typedef vector<int>::iterator viti;
typedef vector<pii>::iterator vitii;
 
int dp[MAXN][MAXN];
 
int main()
{
    //ROP;
    int vmax, cmax, n, i, j;
    scanf("%d%d%d", &vmax, &cmax, &n);
    while (n--)
    {
        int a, b, c;
        scanf("%d%d%d", &a, &b, &c);
        for (i = vmax; i >= a; i--)
            for (j = cmax; j >= b; j--)
                dp[i][j] = max(dp[i - a][j - b] + c, dp[i][j]);
    }
    printf("%d\n", dp[vmax][cmax]);
    return 0;
}

Powered by Jekyll and Theme by solid