洛谷P1616 疯狂的采药
终于出现完全背包了,想的冷笑话可以用了
这个题
完完全全是完全背包啊!!!
#include <iostream> #include <cstdio> using namespace std; int max(int a, int b){ return a > b ? a : b; } int main() { int m, n; cin >> m >> n; int cost[10001] = { 0 }; int value[10001] = { 0 }; for (int i = 0; i < n; i++){ scanf("%d%d", &cost[i], &value[i]); } int pos[100001] = { 0 }; for (int i = 0; i < n; i++){ for (int j = cost[i]; j <= m; j++){ pos[j] = max(pos[j], pos[j - cost[i]] + value[i]); } } cout << pos[m] << endl; return 0; }
一天不做题,浑身难受

浙公网安备 33010602011771号