@[QwQ自动机](/space/show?uid=143834) @[Mist_Stalker](/space/show?uid=60560) @[反比例函数](/space/show?uid=59995) @[我是一个垃圾](/space/show?uid=89396) 来帮下萌新!
by pzc2004 @ 2019-08-07 14:51:51
@[QwQ自动机](/space/show?uid=143834) @[Mist_Stalker](/space/show?uid=60560) @[反比例函数](/space/show?uid=59995) @[我是一个垃圾](/space/show?uid=89396) 过来教教他
by Leap_Frog @ 2019-08-07 14:51:54
@[聪明的猪](/space/show?uid=121479) 您不用
```
using namespace std;
```
吗
by pzc2004 @ 2019-08-07 14:52:08
@[wemspzc](/space/show?uid=60075)
凉凉,上瘾了
by Leap_Frog @ 2019-08-07 14:52:10
@[wemspzc](/space/show?uid=60075)
有人就是不用的
by Leap_Frog @ 2019-08-07 14:52:28
@[聪明的猪](/space/show?uid=121479) 看不懂您写的唉
by pzc2004 @ 2019-08-07 14:52:51
@[QwQ自动机](/space/show?uid=143834) @[Mist_Stalker](/space/show?uid=60560) @[反比例函数](/space/show?uid=59995) @[我是一个垃圾](/space/show?uid=89396) 快来帮一下
by dead_X @ 2019-08-07 14:59:31
好想举报那些随意@别人的人
by Warriors_Cat @ 2019-08-07 15:05:14
用的都是什么STL,正如今日洛谷日报的一句话:
> ~~C++是真的难学呀!~~
此题不用STL,你可以参考以下我的记忆化:
```cpp
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
int n, tm;
int tmarr[105], narr[105];
int mem[103][1003];
const int INF = 2147483647;
int dfs(int pos, int tmleft){
if(mem[pos][tmleft] != -1){
return mem[pos][tmleft];
}
if(pos == n + 1){
mem[pos][tmleft] = 0;
return 0;
}
int a, b = -1;
a = dfs(pos + 1, tmleft);
if(tmleft >= tmarr[pos]){
b = dfs(pos + 1, tmleft - tmarr[pos]) + narr[pos];
}
mem[pos][tmleft] = max(a, b);
return mem[pos][tmleft];
}
int main(){
memset(mem, -1, sizeof(mem));
scanf("%d %d", &tm, &n);
for(int i = 1; i <= n; i ++){
scanf("%d %d", tmarr + i, narr + i);
}
printf("%d", dfs(1, tm));
return 0;
}
```
by 学而思李老师 @ 2019-08-07 15:16:04
什么鬼,看都看不懂!
by HPXXZYY @ 2019-08-07 16:00:53