[洛谷1156]垃圾陷阱(DP)
2024-09-04 17:03:47
f[i]表示高度为i时的存活时间
Code
#include <cstdio>
#include <algorithm>
#define N 110
using namespace std; struct info{
int t,liv,h;
friend bool operator < (info a,info b){
return a.t<b.t;
}
}A[N];
int f[N],dep,n; inline int read(){
int x=0,f=1;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
return x*f;
} int main(){
f[0]=10;
dep=read(),n=read();
for(int i=1;i<=n;++i) A[i].t=read(),A[i].liv=read(),A[i].h=read();
sort(A+1,A+n+1);
for(int i=1;i<=n;++i)
for(int j=dep;j>=0;--j){//注意倒着循环,否则会覆盖上一轮的状态
if(f[j]>=A[i].t){
if(j+A[i].h>=dep){
printf("%d\n",A[i].t);
return 0;
}
f[j+A[i].h]=max(f[j+A[i].h],f[j]);
f[j]+=A[i].liv;
}
}
printf("%d\n",f[0]);
return 0;
}
最新文章
- Android ScrollView与ListView的冲突解决办法汇总
- MSSQL sp_helptextplus
- TimeQuest学习
- 更改linux文件夹的默认颜色
- magento 小问题解决方案集
- windows 下nginx 虚拟主机搭建
- VirtualBox网络的Host-Only配置
- python下划线的5种含义
- C#泛型约束where T : class 解释
- LODOP弹出对话框获取保存文件的路径
- sql in not in 案例用 exists not exists 代替
- Ubuntu18.04的网络配置
- rpc框架实现(持续更新)
- 递归获取包下的class文件
- 转载 IMP时数据库的IO性能监控,并提供IOPS的计算方法
- CSS高级布局
- postgresql----字符串函数与操作符
- OAuth2.0认证和授权以及单点登录
- C++中string.find()函数,string.find_first_of函数与string::npos
- appium+python自动化58-xpath定位
热门文章
- ArcGIS创建要素类
- 【Node.js】初识Node.js
- C语言问题集
- 只为更快、更省、更安全的 Azure CDN
- http相关文章目录
- 在Sql Server中使用Guid类型的列及设置Guid类型的默认值
- 水晶报表分组,统计,求和,sum()函数使用
- Microsoft EDP(enterprise database protection)配置策略中的三种Rule template
- An internal error occurred during: ";Generating JAX-WS Web Services";.Unable to create JAXBContext
- MSMQ学习笔记二——创建Message Queue队列