当前位置:网站首页>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;
}边栏推荐
- Single chip microcomputer -- hlk-w801 transplant NES simulator (III)
- 【视频】马尔可夫链蒙特卡罗方法MCMC原理与R语言实现|数据分享
- Feature extraction and detection 16 brisk feature detection and matching
- Have you stepped on the nine common pits in the e-commerce system?
- Convolutional neural network (including code and corresponding diagram)
- Develop those things: how to use go singleton mode to ensure the security of high concurrency of streaming media?
- New news, Wuhan Yangluo international port, filled with black technology, refreshes your understanding of the port
- Unity AssetBundle subcontracting
- MATLAB realizes voice signal resampling and normalization, and plays the comparison effect
- 如何远程、在线调试app?
猜你喜欢

遊戲思考15:全區全服和分區分服的思考

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

How to use a product to promote "brand thrill"?

Discussion on the idea of platform construction
![[IVX junior engineer training course 10 papers] 05 canvas and aircraft war game production](/img/dc/e9adb1b41c2175c6f18d8027e0530a.jpg)
[IVX junior engineer training course 10 papers] 05 canvas and aircraft war game production

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

Data visualization in medical and healthcare applications

技术大佬准备就绪,话题C位由你决定

PR second training

人工智能在网络安全中的作用
随机推荐
The author is more willing to regard industrial Internet as a concept much richer than consumer Internet
Pyldavis installation and use | attributeerror: module 'pyldavis' has no attribute' gensim '| visual results are exported as separate web pages
How to use a product to promote "brand thrill"?
The role of artificial intelligence in network security
【LeetCode 43】236. The nearest common ancestor of binary tree
[Video] Markov chain Monte Carlo method MCMC principle and R language implementation | data sharing
[Chongqing Guangdong education] Tianshui Normal University universe exploration reference
Study note 2 -- definition and value of high-precision map
KS006基于SSM实现学生成绩管理系统
Memorabilia of domestic database in June 2022
Brief introduction to the development of mobile network
What are the affordable Bluetooth headsets? Student party parity Bluetooth headset recommendation
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
What is AQS and its principle
Single chip microcomputer -- hlk-w801 transplant NES simulator (III)
[rust web rokcet Series 2] connect the database and add, delete, modify and check curd
[disease detection] realize lung cancer detection system based on BP neural network, including GUI interface
6-2漏洞利用-ftp不可避免的问题
Matlab uses audiorecorder and recordblocking to record sound, play to play sound, and audiobook to save sound
开发工具创新升级,鲲鹏推进计算产业“竹林”式生长
