#include <bits/stdc++.h>
using namespace std;
//const int Maxsize=102;
int mem[101][10201];
int P[101];
int F[101];
bool Money[101];
int M,N;
bool flag;
int dp(int in,int Spent)
{
// if(Spent > M && M<1800) return 0;
// if(Spent > m+200) return 0;
if(M > 1800){
if(Spent > M+200) return -1000000;
if(in == N){
if( Spent > M && Spent <= 2000) return -1000000;
else return 0;
}
} else {
if(Spent > M) return -1000000;
if(in ==N) return 0;
}
int &ret=mem[in][Spent];
if(ret!= -1)
return ret;
ret=dp(in+1,Spent);
ret=max(dp(in+1,(Spent+P[in]))+F[in],ret);
return ret;
}
int main()
{
// freopen("in.txt","rt",stdin);
while(cin >> M >> N)
{
flag=true;
memset(mem,-1,sizeof mem);
for(int j=0 ; j<N ; j++)
{
cin>>P[j]>>F[j];
}
cout<<dp(0,0);
cout<<'\n';
}
return 0;
}
Friday, August 8, 2014
Solution for Live Archive 10819 - Trouble of 13-Dots
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment