背包01
#include <iostream>
#include <cstring>
using namespace std;
int max(int x, int y)
{
if( x > y)
{
return x;
}
return y;
}
int main()
{
int t, m, i, j;
int a[1001], b[1001], c[1001];
while ( cin >> t >> m )
{
memset(c, 0, sizeof(c));
for(i = 0; i < m; i++)
{
cin >> a[i] >> b[i];
}
for(i = 0; i < m; i++)
{
for(j = t; j >= a[i]; j--)
{
c[j] = max(c[j], c[(j - a[i])] + b[i]);
}
}
cout << c[t] << endl;
}
return 0;
}
// f[v]=max{f[v],f[v-cost]+weight}