动态规划的引入 P1616 疯狂的采药【完全背包】

题目

https://www.luogu.com.cn/problem/P1616

 

 题目分析

完全背包

代码

#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int f[10000002], v[10002], w[10002];
int main()
{
    int t, m;
    scanf("%d%d", &t, &m);
    for (int i = 1; i <= m; i++)
        scanf("%d%d", &w[i], &v[i]);
    for (int i = 1; i <= m; i++)
        for (int j = w[i]; j <= t; j++)
            f[j] = max(f[j], f[j - w[i]] + v[i]);
    printf("%d", f[t]);
}
posted @ 2020-06-13 20:23  Jason66661010  阅读(140)  评论(0编辑  收藏  举报