Luogu1064 金明的预算方案 (有依赖的背包)
2024-09-08 13:53:38
枚举多个状态
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#define R(a,b,c) for(register int a = (b); a <= (c); ++ a)
#define nR(a,b,c) for(register int a = (b); a >= (c); -- a)
#define Max(a,b) ((a) > (b) ? (a) : (b))
#define Min(a,b) ((a) < (b) ? (a) : (b))
#define Fill(a,b) memset(a, b, sizeof(a))
#define Abs(a) ((a) < 0 ? -(a) : (a))
#define Swap(a,b) a^=b^=a^=b
#define ll long long
//#define ON_DEBUG
#ifdef ON_DEBUG
#define D_e_Line printf("\n\n----------\n\n")
#define D_e(x) cout << #x << " = " << x << endl
#define Pause() system("pause")
#define FileOpen() freopen("in.txt","r",stdin);
#else
#define D_e_Line ;
#define D_e(x) ;
#define Pause() ;
#define FileOpen() ;
#endif
struct ios{
template<typename ATP>ios& operator >> (ATP &x){
x = 0; int f = 1; char c;
for(c = getchar(); c < '0' || c > '9'; c = getchar()) if(c == '-') f = -1;
while(c >= '0' && c <= '9') x = x * 10 + (c ^ '0'), c = getchar();
x*= f;
return *this;
}
}io;
using namespace std;
int w[67][3], val[67][3], items[67];
int f[32007];
int main(){
int V, n;
io >> V >> n;
R(i,1,n){
int v, p, q;
io >> v >> p >> q;
if(q == 0){
w[i][0] = v, val[i][0] = v * p;
}
else{
++items[q];
w[q][items[q]] = v;
val[q][items[q]] = v * p;
}
}
R(i,1,n){
nR(j,V,w[i][0]){
if(w[i][0] == 0) continue;
f[j] = Max(f[j], f[j - w[i][0]] + val[i][0]);
if(items[i] && j >= w[i][1] + w[i][0])
f[j] = Max(f[j], f[j - w[i][1] - w[i][0]] + val[i][1] + val[i][0]);
if(items[i] == 2 && j >= w[i][2] + w[i][0]){
f[j] = Max(f[j], f[j - w[i][2] - w[i][0]] + val[i][2] + val[i][0]);
}
if(items[i] == 2 &&j >= w[i][2] + w[i][1] + w[i][0]){
f[j] = Max(f[j], f[j - w[i][1] - w[i][2] - w[i][0]] +val[i][0] + val[i][1] + val[i][2]);
}
}
}
printf("%d", f[V]);
return 0;
}
最新文章
- 【高级功能】使用canvas元素(第一部分)
- oracle REGEXP_SUBSTR函数
- [LeetCode]题解(python):057-Insert Interval
- Linux下反斜杠号";\";引发的思考
- asp.net 后台对话框,确认跳转
- poj2163
- iOS网络编程笔记——XML文档解析
- vue-项目入门
- Android必知必会-获取View坐标和长宽的时机
- 关于定时器setTimeout()方法的实践--巧解bug
- 第一次OO总结
- Python 3 入门,看这篇就够了
- swift class的虚函数表、扩展、@objc修饰、虚函数的派发方式研究
- 关于QQ的NABCD模型
- Java设计模式(7)装饰模式(Decorator模式)
- shell echo 打印换行
- jsp标签在JavaScript中使用时,可能会出现的一个问题。
- WebView具体介绍
- -Prefix.pch has been modified 的错误修复
- 图像RGB格式与YUV格式互转