luogu 1156 垃圾陷阱 动态规划
2024-09-05 08:14:55
Code:
#include <bits/stdc++.h>
#define N 4004
#define setIO(s) freopen(s".in","r",stdin)
using namespace std;
int f[N];
struct P
{
int t,f,h;
P(int t=0,int f=0,int h=0):t(t),f(f),h(h){}
}t[N];
bool cmp(P a,P b)
{
return a.t<b.t;
}
int main()
{
int D,n,i,j,mx=0;
// setIO("input");
scanf("%d%d",&D,&n);
for(i=1;i<=n;++i) scanf("%d%d%d",&t[i].t,&t[i].f,&t[i].h);
sort(t+1,t+1+n,cmp);
f[0]=10;
for(i=1;i<=n;++i)
{
for(j=D;j>=0;--j)
{
if(f[j]>=t[i].t)
{
if(j+t[i].h>=D)
{
printf("%d\n",t[i].t);
return 0;
}
f[j+t[i].h]=max(f[j+t[i].h], f[j]);
f[j]+=t[i].f;
mx=max(mx, f[j]);
}
}
}
printf("%d\n",mx);
return 0;
}
最新文章
- python成长之路【第十六篇】:JavaScript的高级知识---词法分析
- char *a 与char a[] 的区别
- mysqldump备份与还原mysql数据的实例
- support.SerializationFailedException: Failed to deserialize payload.
- phpStorm设置显示代码行号
- eclipse修改主题配色
- [刷题]算法竞赛入门经典(第2版) 5-13/UVa822 - Queue and A
- Unicode字符集和编码方式
- [译]漫画SELinux概念
- Python 三级菜单 增强版
- 2、java基础
- 配置环境变量及jdk
- 【论文笔记】Malware Detection with Deep Neural Network Using Process Behavior
- Spock - Document -02 - Spock Primer
- Javascript高级编程学习笔记(22)—— 对象继承
- 在Mac上 python中使用tesseract OCR (Pytesser) 识别图片中的文字
- netbeans 正则替换
- oracle数据库无法导出空表的问题解决(开始于oracle11g)
- 【Android病毒分析报告】- 手机支付毒王“银行悍匪”的前世今生
- 使用C语言操作InfluxDB