当前位置:网站首页>734. Energy stone (greed, backpack)
734. Energy stone (greed, backpack)
2022-07-02 01:45:00 【seez】
An energy stone has its own l,e,s, You can think of 01 knapsack problem , because 01 Knapsack is linear recursive , Think about whether there is one Sort Methods , It can make us greedy to get the most energy ?
You can think of the adjacent term exchange method , By exchanging two energy stones , See if you can launch relational

As shown in the figure, we can get the relationship , Get the last order , Make one 01 A backpack will do
#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;
const int N=105;
const int M=1e4+10;
int dp[M];
struct node
{
int s; // Spend time
int e; // energy
int l; // Energy loss
bool operator<(const node b)const
{
return b.l*s<l*b.s;
}
}a[N];
void solve(int g)
{
int n;
int m=0;
cin>>n;
for(int i=1;i<=n;i++)
cin>>a[i].s>>a[i].e>>a[i].l,m+=a[i].s;
sort(a+1,a+1+n);
memset(dp,-0x3f,sizeof dp);
dp[0]=0;
for(int i=1;i<=n;i++)
for(int j=m;j>=a[i].s;j--)
dp[j]=max(dp[j],dp[j-a[i].s]+max(0,a[i].e-(j-a[i].s)*a[i].l));
int res=0;
for(int i=0;i<=m;i++)
res=max(res,dp[i]);
printf("Case #%d: %d\n",g,res);
}
int main()
{
int t;
cin>>t;
for(int i=1;i<=t;i++)
solve(i);
return 0;
}边栏推荐
- 遊戲思考15:全區全服和分區分服的思考
- Since I understand the idea of dynamic planning, I have opened the door to a new world
- Three core problems of concurrent programming
- Matlab uses resample to complete resampling
- 6-3漏洞利用-SSH环境搭建
- The role of artificial intelligence in network security
- Luogu p1775 stone merger (weakened version)
- TSINGSEE青犀平台如何实现同一节点同时播放多个视频?
- C language 3-7 daffodils (enhanced version)
- 【视频】马尔可夫链蒙特卡罗方法MCMC原理与R语言实现|数据分享
猜你喜欢

卷积神经网络(包含代码与相应图解)

基于SSM实现微博系统

Unity AssetBundle subcontracting

What are the skills of spot gold analysis?

三分钟学会基础k线图知识

Six lessons to be learned for the successful implementation of edge coding

matlab 使用 resample 完成重采样

2022年6月国产数据库大事记

Since I understand the idea of dynamic planning, I have opened the door to a new world

matlab 使用 audioread 、 sound 读取和播放 wav 文件
随机推荐
Look at the industrial Internet from a new perspective and seek the correct ways and methods of industrial Internet
Raspberry pie 4B learning notes - IO communication (1-wire)
This is the form of the K-line diagram (pithy formula)
Ubuntu20.04 PostgreSQL 14 installation configuration record
The role of artificial intelligence in network security
电子协会 C语言 1级 33 、奇偶数判断
error: . repo/manifests/: contains uncommitted changes
C language 3-7 daffodils (enhanced version)
The author is more willing to regard industrial Internet as a concept much richer than consumer Internet
The difference between new and malloc
电子协会 C语言 1级 32、计算2的幂
10 minutes to get started quickly composition API (setup syntax sugar writing method)
现货黄金分析的技巧有什么呢?
6-3漏洞利用-SSH环境搭建
Game thinking 15: thinking about the whole region and sub region Services
Electronic Society C language level 1 32, calculate the power of 2
Brief description of grafana of # yyds dry goods inventory # Prometheus
Error creating bean with name ‘stringRedisTemplate‘ defined in class path re
[Video] visual interpretation of Markov chain principle and Mrs example of R language region conversion | data sharing
卷积神经网络(包含代码与相应图解)
