当前位置:网站首页>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;
}
边栏推荐
- Architecture evolution from MVC to DDD
- GL Studio 5 installation and experience
- Should enterprises choose server free computing?
- matlab 使用 audioread 、 sound 读取和播放 wav 文件
- The technology boss is ready, and the topic of position C is up to you
- 电子协会 C语言 1级 32、计算2的幂
- 三分钟学会基础k线图知识
- [rust web rokcet Series 2] connect the database and add, delete, modify and check curd
- 大学的知识是否学而无用、过时?
- [IVX junior engineer training course 10 papers to get certificates] 0708 news page production
猜你喜欢
如何用一款产品推动「品牌的惊险一跃」?
Convolutional neural network (including code and corresponding diagram)
Basic concepts of machine learning
[Maya] the error of importing Maya into Metahuman
MATLAB realizes voice signal resampling and normalization, and plays the comparison effect
With the innovation and upgrading of development tools, Kunpeng promotes the "bamboo forest" growth of the computing industry
matlab 实现语音信号重采样和归一化,并播放比对效果
Matlab uses resample to complete resampling
Matlab uses audiorecorder and recordblocking to record sound, play to play sound, and audiobook to save sound
开发那些事儿:如何利用Go单例模式保障流媒体高并发的安全性?
随机推荐
The difference between new and malloc
开发那些事儿:如何利用Go单例模式保障流媒体高并发的安全性?
10 minutes to get started quickly composition API (setup syntax sugar writing method)
Exclusive delivery of secret script move disassembly (the first time)
[IVX junior engineer training course 10 papers to get certificates] 01 learn about IVX and complete the New Year greeting card
error: . repo/manifests/: contains uncommitted changes
卷积神经网络(包含代码与相应图解)
Android: how can golden nine and silver ten squeeze into the first-line big factories from small and medium-sized enterprises? The depth of interview questions in large factories
Another programmer "deleted the library and ran away", deleted the code of the retail platform, and was sentenced to 10 months
Learning note 24 - multi sensor post fusion technology
C language 3-7 daffodils (enhanced version)
There are spaces in the for loop variable in the shell -- IFS variable
II Basic structure of radio energy transmission system
1217 supermarket coin processor
Réseau neuronal convolutif (y compris le Code et l'illustration correspondante)
三分钟学会基础k线图知识
Implementation of Weibo system based on SSM
Basic number theory -- Gauss elimination
What are the affordable Bluetooth headsets? Student party parity Bluetooth headset recommendation
机器学习基本概念