完全背包 模板
# include <iostream>
# include <cstdio>
# include <cmath>
# include <algorithm>
# include <cstring>
# define rg register
using namespace std;
typedef long long ll;
inline int sread ( )
{
int x= 0 , f= 1 ; char c= getchar ( ) ;
while ( c> '9' || c< '0' ) { if ( c== '-' ) f= - 1 ; c= getchar ( ) ; }
while ( c>= '0' && c<= '9' ) { x= x* 10 + c- '0' ; c= getchar ( ) ; }
return f* x;
}
const int maxn= 1010 ;
int n, V;
int v[ maxn] , w[ maxn] ;
int dp[ maxn] ;
int main ( )
{
n= sread ( ) ; V= sread ( ) ;
for ( rg int i= 1 ; i<= n; i++ )
{
v[ i] = sread ( ) ; w[ i] = sread ( ) ;
}
dp[ 0 ] = 0 ;
for ( rg int i= 1 ; i<= n; ++ i)
for ( rg int j= v[ i] ; j<= V; ++ j)
dp[ j] = max ( dp[ j] , dp[ j- v[ i] ] + w[ i] ) ;
int ans= 0 ;
for ( rg int j= 0 ; j<= V; ++ j)
{
ans= max ( ans, dp[ j] ) ;
}
cout<< ans<< endl;
return 0 ;
}
# include <iostream>
# include <cstdio>
# include <cmath>
# include <algorithm>
# include <cstring>
# define rg register
using namespace std;
typedef long long ll;
inline int sread ( )
{
int x= 0 , f= 1 ; char c= getchar ( ) ;
while ( c> '9' || c< '0' ) { if ( c== '-' ) f= - 1 ; c= getchar ( ) ; }
while ( c>= '0' && c<= '9' ) { x= x* 10 + c- '0' ; c= getchar ( ) ; }
return f* x;
}
const ll p= 2147483648LL ;
int n;
ll dp[ 4010 ] ;
int main ( )
{
n= sread ( ) ;
dp[ 0 ] = 1 ;
for ( rg int i= 1 ; i< n; ++ i)
{
for ( rg int j= i; j<= n; ++ j)
{
dp[ j] = ( dp[ j] + dp[ j- i] ) % p;
}
}
cout<< dp[ n] << endl;
return 0 ;
}