当前位置:网站首页>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;
}边栏推荐
- The difference between new and malloc
- 电商系统中常见的9大坑,你踩过没?
- Learn about servlets
- C language 3-7 daffodils (enhanced version)
- Modeling essays series 124 a simple coding method
- 牛客网——华为题库(51~60)
- Matlab uses resample to complete resampling
- Just using the way and method of consuming the Internet to land and practice the industrial Internet will not bring long-term development
- Fastadmin controls the length of fields in the table
- There are spaces in the for loop variable in the shell -- IFS variable
猜你喜欢

Data visualization in medical and healthcare applications

Memorabilia of domestic database in June 2022

k线图形态这样记(口诀篇)

Learning note 3 -- Key Technologies of high-precision map (Part 1)

Réseau neuronal convolutif (y compris le Code et l'illustration correspondante)

It's already 30. Can you learn programming from scratch?

matlab 使用 audioread 、 sound 读取和播放 wav 文件

Introduction to ffmpeg Lib

Unity AssetBundle subcontracting

如何用一款产品推动「品牌的惊险一跃」?
随机推荐
Failed to transform file 'xxx' to match attributes
大学的知识是否学而无用、过时?
1218 square or round
2022年6月国产数据库大事记
Implementation of Weibo system based on SSM
如何远程、在线调试app?
Makefile simple induction
Altium designer measure distance (ctrl+m)
Automatically browse pinduoduo products
Ks006 student achievement management system based on SSM
[IVX junior engineer training course 10 papers to get certificates] 01 learn about IVX and complete the New Year greeting card
开发那些事儿:如何利用Go单例模式保障流媒体高并发的安全性?
What are the affordable Bluetooth headsets? Student party parity Bluetooth headset recommendation
np. Where and torch Where usage
[rust web rokcet Series 1] Hello, world and get, post, put, delete
Edge computing accelerates live video scenes: clearer, smoother, and more real-time
matlab 使用 audiorecorder、recordblocking录制声音,play 播放声音,audiowrite 保存声音
MATLAB realizes voice signal resampling and normalization, and plays the comparison effect
The difference between new and malloc
Learn basic K-line diagram knowledge in three minutes
