$f$数组开小了,应该是$1020$的,因为$T$最大时是$1000$。
p.s. $n$,$m$开$int$就够了
像这样
```cpp
#include<bits/stdc++.h>
using namespace std;
int n,m;//int就够用了
int t[220],w[220],f[1020];
int main() {
cin>>m>>n;
for(int i=1; i<=n; i++) cin>>t[i]>>w[i];
for(int i=1; i<=n; i++) {
for(int j=m; j>=t[i]; j--) {
f[j] = max(f[j],f[j-t[i]]+w[i]);
}
}
cout<<f[m];
return 0;
}
```
by 2simon2008 @ 2021-05-19 18:57:19
[通过记录](https://www.luogu.com.cn/record/50871603)
~~虽然是我小号交的~~
@[cs_xy](/user/397727)
by 2simon2008 @ 2021-05-19 19:00:15
f 数组记得开1005啊,T≤1000!!
$n,m$开$int$即可,$t$,$w$ 数组开105即可。
像这样
```cpp
#include<bits/stdc++.h>
using namespace std;
int n,m;
int t[120],w[120],f[1020];
int main() {
cin>>m>>n;
for(int i=1; i<=n; i++) cin>>t[i]>>w[i];
for(int i=1; i<=n; i++) {
for(int j=m; j>=t[i]; j--) {
f[j] = max(f[j],f[j-t[i]]+w[i]);
}
}
cout<<f[m];
return 0;
}
```
by _Harrisonwhl_ @ 2021-05-19 19:03:22
修改后可以[AC](https://www.luogu.com.cn/record/50872290)
by _Harrisonwhl_ @ 2021-05-19 19:05:33
谢谢
by cs_xy @ 2021-05-22 09:18:15