麻烦各位大佬帮忙解答一下,谢谢!
by yuyuyuyu12345 @ 2020-03-11 17:11:54
```
return mem[num][rest]=maxn;//返回值的同时存储这次运算的返回值
```
求解这步为什么要存储这次运算的返回值
by yuyuyuyu12345 @ 2020-03-11 17:13:07
@[yuyuyuyu12345](/user/324176)
```
#include<iostream>
#include<algorithm>
using namespace std;
struct qp
{
int gao;
int tili;
}n[5002];
bool pq(qp n,qp y)
{
return n.tili<y.tili;
}
int main()
{
int a,b,c,d,e=0;
cin>>a>>b>>c>>d;
d=d+c;
for(int i=1;i<=a;i++)
{
cin>>n[i].gao>>n[i].tili;
}
sort(n+1,n+1+a,pq);
for(int i=1;i<=a;i++)
{
if(n[i].gao<=d&&b-n[i].tili>=0)
{
b-=n[i].tili;
e++;
}
}
cout<<e;
return 0;
}
```
by PrincessYR✨~ @ 2020-03-11 17:14:27
@[yuyuyuyu12345](/user/324176) 记忆化,算过的就不再算一遍了
by jijidawang @ 2020-03-11 17:16:07
@[jijidawang](/user/227514) 可是这题不需要记忆化啊(难道是我太弱了)
by vectorwyx @ 2020-03-11 17:36:06
@[vectorwyx](/user/238408) ~~题解可能想炫技~~
by jijidawang @ 2020-03-11 17:41:36
@[jijidawang](/user/227514) 谢谢!
by yuyuyuyu12345 @ 2020-03-11 22:47:10
@[PrincessYR✨~](/user/183473) 谢谢!
by yuyuyuyu12345 @ 2020-03-11 22:47:23
题解前面的大佬比较多。。可能理解会有问题。。
献上本人的代码。。。这题有点类似排队接水那道题。。
```cpp
```#include <iostream>
#include <algorithm>
#include <cstdio>
using namespace std;
struct apple{
int high,power;
}e[8000];
bool cmp(apple p1,apple p2){
if(p1.high==p2.high){
return p1.power<p2.power;
}
return p1.power<p2.power;
}
int n,s,a,b,ans;
int main(){
cin>>n>>s>>a>>b;
ans=0;
for(int i=0;i<n;i++){
cin>>e[i].high >>e[i].power;
}
sort(e,e+n,cmp);
for(int i=0;i<n;i++){
if(a+b>=e[i].high && s>=e[i].power){
s-=e[i].power;
ans++;
}
}
cout<<ans;
return 0;
}
by Poiyzy @ 2020-03-13 16:32:19