hdu 3466 Proud Merchants
题目:http://acm.hdu.edu.cn/showproblem.php?pid=3466
思路:贪心对当前能取的,q-p较小的优先考虑

#include <cstring> #include <iostream> #include <algorithm> #include <cmath> #include <cstdio> #include <queue> using namespace std; #define maxn 500005 int dp[maxn]; struct thing { int p,q,v; }t[510]; bool cmp(thing a,thing b) { return (a.q-a.p)<(b.q-b.p); } int main() { int n,m; while(scanf("%d%d",&n,&m)!=EOF) { for(int i=1;i<=n;i++) scanf("%d%d%d",&t[i].p,&t[i].q,&t[i].v); sort(t+1,t+n+1,cmp); memset(dp,0,sizeof(dp)); for(int i=1;i<=n;i++) for(int j=m;j>=t[i].p;j--) if(j>=t[i].q) dp[j]=max(dp[j],dp[j-t[i].p]+t[i].v); printf("%d\n",dp[m]); } return 0; }
【推荐】还在用 ECharts 开发大屏?试试这款永久免费的开源 BI 工具!
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步