枚举多个状态

#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;
}

最新文章

  1. 【高级功能】使用canvas元素(第一部分)
  2. oracle REGEXP_SUBSTR函数
  3. [LeetCode]题解(python):057-Insert Interval
  4. Linux下反斜杠号&quot;\&quot;引发的思考
  5. asp.net 后台对话框,确认跳转
  6. poj2163
  7. iOS网络编程笔记——XML文档解析
  8. vue-项目入门
  9. Android必知必会-获取View坐标和长宽的时机
  10. 关于定时器setTimeout()方法的实践--巧解bug
  11. 第一次OO总结
  12. Python 3 入门,看这篇就够了
  13. swift class的虚函数表、扩展、@objc修饰、虚函数的派发方式研究
  14. 关于QQ的NABCD模型
  15. Java设计模式(7)装饰模式(Decorator模式)
  16. shell echo 打印换行
  17. jsp标签在JavaScript中使用时,可能会出现的一个问题。
  18. WebView具体介绍
  19. -Prefix.pch has been modified 的错误修复
  20. 图像RGB格式与YUV格式互转

热门文章

  1. Vue2框架
  2. 纯CSS如何禁止用户复制网页的内容?
  3. IIS7 网站发布常见报错问题解决方案汇总
  4. Spring Ioc源码分析系列--Bean实例化过程(二)
  5. springcloud 断路器
  6. 【抬杠C#】如何实现接口的base调用
  7. 2 Elment Ui 日期选择器 格式化问题
  8. React与Koa一起打造一个功能丰富的全栈个人博客(业务篇)
  9. .NET程序配置文件操作(ini,cfg,config)
  10. VScode运行总是显示running状态