#include<iostream>
using namespace std;
int main()
{
int cash,n,max;
while(cin>>cash>>n)
{
max = 0;
int m[1001],v[1001];
for(int i = 0;i<n;i++) cin>>m[i]>>v[i];
bool dp[100001];
memset(dp,0,sizeof(dp));
dp[0] = true;
for(int i = 0;i<n;i++)
{
for(int j = max;j>=0;j--)
{
if(dp[j])
{
for(int k = 1;k <= m[i];k++)
{
int tmp = j+k*v[i];
if(tmp>cash) break;
dp[tmp] = true;
if(tmp>max) max = tmp;
}
}
}
}
cout<<max<<endl;
}
return 0;
}
POJ1276
最新推荐文章于 2021-02-25 09:33:50 发布