链接:https://www.luogu.com.cn/problem/P1853
题目:
总的思路就是完全背包模板加上空间优化
完全背包参考:https://blog.csdn.net/qq_40802813/article/details/119609917
空间优化见代码
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<vector>
#include<algorithm>
#include<math.h>
#include<sstream>
#include<string>
#include<string.h>
#include<iomanip>
#include<stdlib.h>
#include<map>
#include<queue>
#include<limits.h>
#include<climits>
#include<fstream>
#include<stack>
typedef long long ll;
using namespace std;
const int N = 1e7 + 1e5;
int n, C, dp[N];
int w[N], c[N];
int times;
int main()
{
ios::sync_with_stdio(false); cin.tie(0), cout.tie(0);
int d;
cin >> C >> times >> d;
for (int i = 1; i <= d; i++)
{
cin >> c[i] >> w[i];
}
for (int i = 0; i < times; i++)
{
int m = C / 1000;//这里!
for(int i=1;i<=d;i++)
for (int j = c[i]/1000; j <= m; j++)//以及j<=m
{
dp[j] = max(dp[j], dp[j - c[i]/1000] + w[i]);
}
C = dp[m] + C;
}
cout << C;
return 0;
}
标签:最大,int,long,times,效益,https,P1853,include
From: https://www.cnblogs.com/zzzsacmblog/p/18213094