直接朴素二维
#include <iostream>
#include <cstdio>
using namespace std;
const int N = 1010;
int f[N][N];
int t[N],w[N];
int n,m;
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=0;j<=m;j++)
{
f[i][j]=f[i-1][j];
if (j>=t[i]) f[i][j]=max(f[i][j],f[i-1][j-t[i]]+w[i]);
}
cout<<f[n][m]<<endl;
return 0;
}