题目标签我觉得有问题

P1048 [NOIP2005 普及组] 采药

能看一下代码吗,学习一下dalao的贪心做法
by CreeperK @ 2018-08-27 10:31:00


你用贪心做没WA吗???反正我用的是动规
by wxy_god @ 2018-08-27 10:31:14


萌新求教,如何用贪心做01背包问题
by chen_zhe @ 2018-08-27 10:31:26


巨佬 贪心怎么做啊
by tumu1t @ 2018-08-27 10:34:54


dalao,请问贪心怎么做这题
by Yuno @ 2018-08-27 10:43:40


好吧好吧~~看错了~~
by Crazy_Lin @ 2018-08-27 10:44:48


#include<bits/stdc++.h> using namespace std; int n,s,a,b,ans=0,t1,t2; int xi[5010],yi[5010]; int main(){ cin>>s>>n; for(int i=1;i<=n;i++) cin>>xi[i]>>yi[i]; for(int i=1;i<n;i++) for(int j=i+1;j<=n;j++){ if(yi[i]<yi[j]) { swap(xi[i],xi[j]);swap(yi[i],yi[j]); } } for(int i=1;i<=n;i++){ if(xi[i]<=s) { ans+=yi[i]; s-=xi[i]; } } cout<<ans; return 0; }
by Crazy_Lin @ 2018-08-27 11:15:22


```cpp #include<bits/stdc++.h> using namespace std; int n,s,a,b,ans=0,t1,t2; int xi[5010],yi[5010]; int main(){ cin>>s>>n; for(int i=1;i<=n;i++) cin>>xi[i]>>yi[i]; for(int i=1;i<n;i++) for(int j=i+1;j<=n;j++){ if(yi[i]<yi[j]) { swap(xi[i],xi[j]);swap(yi[i],yi[j]); } } for(int i=1;i<=n;i++){ if(xi[i]<=s) { ans+=yi[i]; s-=xi[i]; } } cout<<ans; return 0; } ```
by Crazy_Lin @ 2018-08-27 11:15:36


贪心解法10分。。。
by Crazy_Lin @ 2018-08-27 11:15:54


@[林佐佑](/space/show?uid=87437) +1![](C:\Users\Administrator\Desktop\猪仔大老爷)
by Tobo @ 2018-09-17 14:57:26


| 下一页