-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path10819.cpp
More file actions
44 lines (40 loc) · 994 Bytes
/
Copy path10819.cpp
File metadata and controls
44 lines (40 loc) · 994 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
#define INF int(1 << 30)
int cost[105],fav[105];
int res[105][10505];
int dp( int m , int n , int pos , int cc )
{
if( pos == n )
{
// cout << cc << " " << m << " " << ( ( cc-m > 0 && cc > 2000 ) || ( cc <= m ) ? 0 : -INF )<< endl;
return res[ pos ][ cc ] = ( cc-m > 0 && cc > 2000 ) || ( cc <= m ) ? 0 : -INF ;
}
if( res[ pos ][ cc ] != -1 )
return res[ pos ][ cc ];
int a,b;
int sum = cc + cost[pos];
if( sum <= m+200 )
a = dp( m , n , pos + 1 , sum ) + fav[pos];
else
a = -INF;
b=dp( m , n , pos + 1, cc );
// cout << "pos " << pos << " a " << a << " b " << b << endl;
return res[ pos ][ cc ] = max( a , b );
}
int main()
{
int n,m;
while( scanf("%d %d",&m,&n ) != EOF )
{
for( int i = 0 ; i < n ; ++i )
{
scanf("%d %d",&cost[i],&fav[i] );
}
memset( res , -1 , sizeof res );
printf("%d\n", dp( m , n , 0 , 0 ) );
}
return 0;
}